Btw, on the inventory_array slots array variable, I imagine that is on a node and you are plugging in assets into the slots array, what assets are you plugging into those, what type or resource are they?
Maybe you plugged in an inventory_item asset instead of an inventory_slot asset?
If I understand what you’re saying correctly, I think I’m plugging in resources as seen below. When I posted this I had an apple resource in slot 0 and it considered that an ‘inventory_item’. I switched it back to an empty resource and I get the same error but instead it says unable to cast object of type error ‘godot.resource’ to type ‘inventory_slot’.
Something to take note of, maybe, is that when I changed the code in UpdateSlots to this it doesn’t give a type error:
inv.Slots[i] = new inventory_slot();
inventory_visual slotScript = slots[i].GetNode<inventory_visual>(".");
slotScript.Update(inv.Slots[i]);
However it creates new inventory_slots every time UpdateSlots is called which is most likely a problem and isn’t a solution. I went to collect an apple in game and it didn’t show up in the inventory.
It is possible, that C# has stricter rules about typed arrays, than GDScript has. So not everything that works in GDScript may work in C# in the same way.
so yeah, that is why I think what you have plugged into that player inventory array are not all inventory_slot resource types. If you click on one of those, or expand that window, what do you see?
That looks like an inventory_item resource and not an inventory_slot resource as ‘Name’ is one of the properties, that array takes inventory_slot resources right?
I mean on the node where you drag and drop the resource into each element, if the array type is inventory_slot but you drop in an inventory_item resource, you will get that error.
It’s attached to the player node, if that’s what you meant? I’m new to Godot and C# so not completely familiar with everything. I still get that error despite whether it’s a resource or an inventory_item though.
so that array Slots has 20 elements in it, I imagine you dragged and dropped some resource files into those slots? Check to make sure they are inventory_slot resources and not inventory_item resources, as that array only takes inventory_slot resources.
then you can see what type of resource it is, the script on that resource should be inventory_slot, at least that is what the Slots array is looking for.
Essentially what I did was for every slot is added a New Resource but I didn’t drag anything into them except for when I added an inventory_item to see what would happen.