+1 vote

I have an NPC node that is a tool and one of its script variables has a setter function attached that takes a string and uses it to find a sprite image (saved a .PNG) in the game folder to choose its sprite. I type in something like "CITPED2" and it looks inside the folder to find PED2.PNG in the CIT folder.

enter image description here

However, the line of script that sets the texture always returns an error:

enter image description here

 Node not found: Sprite
 res://Maps/Actors/{Scripts/NPC.gd:28 - Attempt to call function 'set_texture' in base 'null instance' on a null instance.

From what I read of this error, the function is not recognizing the Sprite and returning it as a 'null instance'. It's weird because despite getting an error, the script does was its supposed to do. In the editor, when I change the sprite_sheet variable (and the string is a valid location), the Sprite's Texture changes without any other problems! But running this game is impossible because that error comes up on runtime just as it does in the editor.

I'm not sure what causes it, but if I remove that line changing the texture then I don't get the error.

The error doesn't pop up whenever I change the sprite_sheet variable, but whenever I save or load in the node. Maybe there's something about what happens to a tool during save time that could enlighten us, but I'm still learning how tools work.

So I'm guessing this has to do with either setter functions or how tool nodes function in the editor. I've been trying at this for awhile and I'm really out of ideas. I couldn't find the help I needed.

asked Mar 30, 2019 in Engine by DoubleCakes (28 points)
retagged Mar 30, 2019 by DoubleCakes

1 Answer

0 votes

Did you find any solution?

answered Nov 8, 2019 by Amir Rezaei (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.