Help with .visible = true error

Godot Version 4.2.2

Question

I’ve been down the rabbit hole and ready 10s of threads about this and still can’t fix it. Apologies because it seems like it should be really simple.

After a dialogic conversation, I want to toggle the visibility of an interaction prompt to true. In this case a Sprite2D called “defib_prompt” originally I had it in another scene but suspected that could cause the issue so moved it into the main scene. It’s a very small game so the clutter isn’t and issue.

func _on_dialogic_signal(argument:String):
	if argument == "defib_required":
		print("defib required!")
		%defib_prompt.visible = true

The func works right up to printing “defib required!” then crashes and gives me

Invalid set index ‘visible’ (on base: ‘null instance’) with value of type ‘bool’.

From the countless threads I’ve read I understand this means that the Sprite2D node doesn’t exist at the time of execution but I’m struggling to translate that info into a solution.

help would be greatly appreciated, if you can ELI5 that would be even better.

thanks in advance.

It means that the node “%defib_prompt” is null, it can be for different problems. Try to debug your game while running in remote section, check is it really exist?

You said this object was on another scene at some point?
Where does this function reside? Whose script?

this code is in my game manager which is an auto load.

i don’t understand why it wouldn’t be in the scene. it’s there in the tree and on-screen when I run the game. there aren’t any scene loads or anything in between that would result in it being destroyed.

The problem must be that you are calling the node using the “%” shorthand from another scene (the game mananger autoload).

1 Like

You just need to replace the last line with this code:

$".".visible = true

Use the dot to refer to the node connected to the script.

i moved the code into the script for the level and the visible is now working, however when it’s made visible it’s at the left most point of the level for some reason. At least I’m onto a different issue. Thanks.

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