Hello !
I’m starting to learn Godot with some C# and I have a weird resource casting issue.
Might be related to garbage collection but I don’t know enough about Godot and don’t remember enough about c# X).
So I just wanna spawn some dominos.
so I have this class :
in an array in another custom resource :
Everything is created at edit time in the editor and only accessed at runtime.
At some point I need to get the material associated with a type so I call this method twice :
which runs fine both times.
And I manage to spawn my first domino.
I can see in memory that the 4 RegionSettings are of the right type in their array :
It’s hard to debug this issue without having access to all the code for your system. Beyond using != instead of IsInstanceValid(), I don’t see anything weird in your code. It does look like you are using some extension methods which are undisclosed.
If you want more than a guess as to what is wrong, please provide more of the relevant code.
ok so I got a bit more info since then.
Commenting the Init Method made it not trigger the exception, so I commented some lines in it and found the culprits :
Before I gave the material in my ressource to some meshes, and it somehow messed with the ressources.
Now I duplicate the Material and I don’t get any issue.
That at least unblocks me, but I still find it a bit worrying that I don’t understand what was happening. ^^’
Even if the mesh somehow needs full ownership of the Material instance, I don’t see why it would invalidate the resource and not just the Material pointer.
For now I just want to color my dominos by type, so sharing the same materials across all meshes seemed fine but maybe they need to be unique ?