Godot Inspector Unable to Assign PackedScene Array Elements in C#

Godot Version

4.3

Godot Inspector Unable to Assign PackedScene Array Elements in C#

Hi guys, I’m having a very weird issue. I’m programming in C#, and I’d like to have an array of PackedScenes exported to the inspector. The export works fine, but when I try to assign a scene to one of the array elements in the inspector, this error pops up in my log:

Attempted to set an object of type 'PackedScene' into a TypedArray, which does not inherit from 'Node'.
core/variant/array.cpp:429 - Condition "!_p->typed.validate(value, "set")" is true.

And here is my export code:
[Export]
PackedScene[] scenes;
I’ve tried changing it to a Godot.Collections Array, but that also did not work. A regular export of just one PackedScene works fine, it’s just this array that for some reason doesn’t work. The Godot docs say this should work (C# exported properties — Godot Engine (stable) documentation in English), I tried it like they said, it just didn’t work.

Is this is C# or a Godot 4.3 specific issue? I’m not sure what could be causing this. Please let me know if any of you have experienced an issue like this, and let me know if you need any more specifics! Thank you!

Hmmm… I tried to reproduce the bug myself, trying out multiple things that could maybe cause the issue but… nothing. At first I thought it was maybe a missing public in front of the array declaration but it doesn’t seem to be necessary.

I did some further research and found this post. Looks like somebody has already had the same problem, just in GDScript. Restarting Godot seemed to do the trick. If you’re lucky, that will work for you too. ^^

If the problem still persists, I would check the scene you are trying to drag in. Check for any errors in the root node’s script. Maybe it is not inheriting from Node properly. But that can’t really be it either if you say just a single PackedScene works while the array doesn’t.

1 Like

I solved it, it looks like it’s just a weird bug or a benign C# design choice for the engine. As it turns out, there was nothing wrong with my script. I tested it on another machine, on both 4.1 and 4.3, it worked on both, then went back to my original computer, tested it after turning it on and off, still didn’t work. So, I recreated the script, copied the exact code from my original script (minus two using statements that weren’t being used), and then it worked. So I guess the answer was just to recreate the script, there was some kind of bug in how it was made? I don’t know, but it works now. Not really sure what changed!

I can speculate only but maybe was something inside array different than PacketScene. Godot allow in some situations put wrong types in inspector.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.