for Godot 4: in inventory script it has to be @onready var inventory_slots in the ready function is inv_slot.gui_input.connect(slot_gui_input.bind(inv_slot)) in the for loop (inventory script) MOUSE_BUTTON_LEFT instead of BUTTON_LEFT instantiate() instead of instance set("theme_override_styles/panel") in the refresh_styles function
There is another new difference in the tutorial for Godot4. When you are chaning the hotbar slot background based on whether or not it is occupied: You have to use "set('theme_override_styles/panel', style)" instead of "set('custom_styles/panel', style)"
Thanks for this, I had a feeling it should look vaguely like that but I was fumbling around in the dark for half an hour trying different variations before I spotted this comment and it worked perfectly.
Not declared in current scope means the variable name is either incorrect, not referenced, or was never created. Check how/where that variable is created :)
Useful tutorial. One important point to note is that the order of calling remove_child() and add_child() matters. You can't have one node shared by several parents. So you need to make sure you always first remove a node from one parent before adding it to another. What I didn't like about the example code here was the direct accessing of the parent Inventory node from Slot nodes (and not only accessing, but modifying its state). It's like spooky action at distance - Inventory asks the Slot to do something, and the Slot ends up modifying the Inventory. I reorganized the code so that pickFromSlot() and putIntoSlot() only add/remove nodes from Slot, while the Inventory takes care of adding/removing its own nodes. I also found it more natural to have the pickFromSlot() return the item it removed.
Great simple tutorial. For anyone following the tutorial. In the putIntoSlot function, don't forget the remove_child line. I spend half of my night figuring out why item.position = Vector2(0,0) was putting my items at the origin after moving them around slots, and that was the missing line. @Arkeve, not going to lie (and I've seen a few other comments about this), I have no idea why some of this works. A little explanation on things like why setting the position to (0,0) works for instance would really help noobs like myself understanding. Having said that, awesome tutorial, thanks for putting in the effort to make this whole series.
I don’t think you understand how long I’ve been searching for a tutorial that works EXACTLY like this. But it also explains the mouse filter. Thanks a lot. Can’t wait for the new ones!
Even though the community made tutorials for godot are kind of lacking, it's good to see people starting to make more content. Hope we'll get to the level of unity in terms of content. That would be fantastic.
This is one of the best tutorials on how to make a basic inventory. Most tutorials stretch over 30 min and if you dont know any coding you dont want to see 30 mins of that
Actually yes you do want to see 30 minutes of that. You need to learn somehow and if the person is just copy and pasting a bunch of code you're learning nothing whatsoever which defeats the entire purpose
Really good tutorial. But if I could make a sugestion, could you spend more time explaining the functions and their processes a bit more? It would more helpful for beginer/intermediate GDscript users who might not be that familar with what is exactly going on.
for those getting the error: "attempt to call function add_child in base null" make sure you have the correct capitalization for the find_parent("Inventory") part. I named my node 'inventory' with a lowercase I and got the error above because I copied to code from the video with the capital I. as soon as I changed that to a lowercase I in both the pickFromSlot and putIntoSlot it worked and I no longer got that error.
very good tutorial bro but I have a problem. I'm following this in Godot 3.4 and when I run the project I got the 'Attempt to call function 'add_child' in base 'null instance' on a null instance.' error for inventoryNode. add_child(item) line in slot.gd. Can you help me?
Man, I have a huge amount of code to generate a grid of slots... I really should just be using containers... Nice vid. A lot more simplified than my implementation, which has already had 2 refactors and likely needs yet another after watching this. Hah.
I've been getting the following problem (Godot Ver. 3.5.1), it says "attempt to call function 'get_node' in base 'null instance' on a null instance". Turns out, I had the GridContainer as a node/ child of TextureRect. So: Inventory>TextureRect>GridContainer (meaning GridContainer is a grandchild of Inventory). It should be Inventory>TextureRect as well as Inventory>GridContainer. This solved the problem for me. I thought I'd mention it, since other people here in the comments seem to have the same problem. Happy coding to yall (:
So the last part worked for you? Kinda getting stuck in 4.0, tryin got connect the signal in the inventory _ready() function. Would love to know what the solution would be!
@@Arkeve for some reason I'm finding myself unable to click around the inventory in my game even though it works normally when I open up the inventory scene isolated. Any idea what might be causing the issue?
Great tuorial , but the only problem I am having is running get_global_mouse_position(), the engine is saying that the method isn't declared in the current class
Id suggest making an update version if this since people have said some things have changed since the update and people also wished for more rxplsnstion for beginners. I like this video do id be happy to see another version of it :)
Okay .. um i was facing an error with the get_global_mouse_position.. thing... so what i did was $"(name of node containing panel)".get_global_mouse_position() Edit: Clicking an item twice ... is breaking the inventory. :( I guess Ishould make another if to fix that?
hi @Arkeve, in my opinion, this is the best tutorial for beginner that have zero coding knowledge like me.... ty ^^... but i wanna ask u something... how to change mouse button input into touch screen? for examples if we want to export it to android or ios...
After the ready function towards the end of the video in Inventory.gd, I keep getting an error at for inv_ slot. it says: Attempt to call function 'get_child' in base 'null instance' on a null instance.
Awesome tutorial for Godot! I love it! Is this inventory system safe against duplication of items? And can you expand on it to build a game where machines have an inventory and that one can interact with? Similar to a Furnace in Minecraft? Is it also possible to make a currency system? I such a n00b when it comes to coding! :-P
Exactly what I am looking for. I hope this works, other tutorials I checked did not provide the inventory system I would like to have. Edit: [08:10] What is "gui_input"?
so i have this disorder where my code doesen't work when i type it but when copy pasting it it just works and it left me with a wtf moment. any relatables?
hello, I've tried re-writing the slot_gui_input function so that pick-up is performed when clicking but put-in-slot functions happen when releasing the input, I just can't make it work for the life of me, it just returns the item to the original slot. Picking up works perfectly fine
i can't run the code! "Parser Error : The method "get_global_mouse_position" isn't declared in the current class." the code is the same as yours, as i get it into that video
The project does not work it says Line 10:Identifier "File" not declared in the current scope. Line 12:Identifier "File" not declared in the current scope.
I'm getting an error under the put_into_slot function at item.position = Vector2(0, 0), where it says "Invalid set Index 'position' (on base Nil) with value of type Vector2". When i open the inventory and click on an icon to pick it up my game crashes and I get this error. What could it mean?
Hey man, I followed the tutorial as closely as I could, but when I load up my inventory screen and click an item, the scene crashes and I get the error “ Attempt to call function ‘add_child” in base ‘null_instance” on a null instance’ “ in my Slot.gd script. I found a loophole by declaring “onready var inventoryNode = find_parent(“Inventory”)” at the top of my Slot.gd script and disabling the middle two lines in “func pickFromSlot” and “func putIntoSlot”, and it doesn’t crash, but I can’t actually drag my items around, only click them into different boxes. Is this a different issue? Any way to fix this? I’m pretty new to Godot so I’m not really sure what I’m doing yet.
no idea if you figured this out already, but I had the same issue for agggges and it turns out I had just capitalized "Inventory" when my actual node was lowercase ("inventory"). so if i understand correctly, it was calling a node that wasnt there and returning null, hence the "null instance" bit. maybe this helps?
@@panicasherpanic6776 You probably Misspelled Inventory wrong along the way. Also if you already Added your missspelled "Invnetory" Scene into another scene and changed the name afterwards to be correct it doesn't get updated.
im fresh to godot so a noob question - say I had an RTS type of game and wanted to add inventory systems to all the characters, would I attach this node to the nodes for each character? (Ignore that this is probably not performant). Or is this more from the perspective of a World parent node, and one playable character uses it?
I am recieving this error, any idea how to solve this? thanks? E 0:00:31.433 emit_signal: Error calling method from signal 'gui_input': 'Node2D(Inventory.gd)::slot_gui_input': Method not found..
Hey, I found the tutorial great and very clear, but my program doesn’t work and I can’t for the life of me figure out why. The icons appear correctly but as soon as I click on one of them it disappears, then I can’t do anything anymore. Do you maybe know what’s that related to, thx in advance.
I need a little bit help. If i start my game, the debugger shows me following: Invalid get index 'Slime Potion' (on base: 'Dictionary') on item.gd. Sometimes it's Iron Sword, sometimes Tree Branch. Any ideas? Second Failure: Same as first, but on Slot.gd on the "add_child(item)" line straight after "if randi() % 2 == 0: item = ItemClass.instance()"
hey can you explain a bit what is that you are doing for the default_style: StyleBoxTexture and the empty_style: StyleBoxTexture? cause those are variables you created but you arent assigning stuff to them i havent really seen the colon being used like that with variables before
7:30 how did we come up with item = new_item ? when I type that in, I get and error (The identifier "new_item isn't declared in the current scope. Anyone else with that problem?
This is a late reply but try adjusting the scale setting of the sprites. I think it has to do with your sprites being hypothetically 64x64 while the inventory slot is 32x32
Hi, great tutorial, thank you! I was trying to make it similar to yours, but so that you don't click to pickup then click to drop, but you drag and drop. The problem I found is that the mouse release event triggers on the same panel on which you pressed it, but not the panel you have your mouse on when releasing, Bloody annoying. Does anyone know of any workaround for that? Thanks
just when you release the mouse a InputEventMouseMotion event appear (for the other panel), so you should can check if the last event was a left click release, there is my code: var last_event : InputEvent = null var last_slot : SLOT_CLASS = null func slot_gui_input(event : InputEvent, slot : SLOT_CLASS): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT && event.pressed == true: if holding_item != null: #On Put OnPutItem(event, slot) elif slot.item: # On Pick OnPickItem(slot) last_event = event last_slot = slot # On release elif event is InputEventMouseMotion: if last_event != null: if last_event.button_index == BUTTON_LEFT && last_event.pressed == false: if holding_item != null: OnPutItem(event, slot, last_slot) func OnPutItem(event : InputEvent, slot : SLOT_CLASS, slot2 : SLOT_CLASS = null): if !slot.item: #Put on empty slot slot.PutIntoSlot(holding_item) elif slot.item and slot2 != null: # Swap items slots var temp_item = slot.item slot.RemoveItem() slot.PutIntoSlot(holding_item) slot2.PutIntoSlot(temp_item) #slot2 is a empty slot before OnPickItem holding_item = null
@@agriasoaks6721 the item should be a Node2D (not a texture rect) because it has a global_position property. Try to do exactly the tutorial so that you understand the solution.
great tutorial really easy to get along to but i feel like its kinda inefficient to preload the item can adding a button to the item scene and set one var into an array of the panels and for loop checking of all of them is null then if it isnt then when on click event happens you just code in the variable to set the preload into the item that was clicked on or is this less efficient and impossible anywaays great vid hope you make more
Yeah you maybe right, I wasn't focusing too much on performance with these tutorials, you can definitely try to modify it to how you like for a better performing system!
When I put in the code I can get the randomized items but it never lets me move them I keep checking I tried copying and pasting from the one thats in the zip file but it gives me an error and when I type it out it doesn't even do anything and gives me errors I dont know how to fix
i have exactly copied your "Item" code and i get this error Script inherits from native type 'Node2D', so it can't be instanced in object of type: 'Panel' why is this? EDIT: The erro was because i am an idiot. It was because i chose the "Item" script for my panels.
Iv been working for days on my inventory in unity. I also have a way to save my player data. Was wondering if it would be worth it or if its easier to transfer my progress to godot with all these available tutorials now.
Hi! I'm a beginner and I'm studying these scripts to improve my "syntax". There's a particular line i I'm struggling with. It's the 15th line in the inventory.gd script: If !slot.item: I didn't know you could use "!" in that way. So far I had only used it in the "!=" expression. Could anyone explain to me what is that line really "saying" and where could i find more information about that usage of "!"? I've tried with the official documentation with no luck.