Godot Version
v4.3.stable.official [77dcf97d8]
Question
Hello! I got this error: Attempt to call function ‘add_effect’ in base ‘null instance’ on a null instance. I know that its usually an error related to the $player not being correct but I think that the problem comes from instantiating the scene from a tilemap node instead of from the main scene. Is there a fix for that?
Solution: If anyone is having this issue, it’s because nodes from the scene collection of tilemaps are considered children of said tilemap. To fix, just drag in a scene and make it a child of the tilemap. Then you can connect it to whatever and it should re-organize itself. After that, you can safely delete the scene node again.
i think what you meant to write was this:
player.add_effect("slow")
instead of this:
$player.add_effect("slow")
you put a “$”, which doenst belong there
Unfortunately, that didn’t fix it, as it still crashes from the bug. Thanks, though!
Is the error message still the same? You can try to use the @export property instead of the @onready. Then you can set the player yourself
Yeah same error. It can’t actually work because im using a tilemap so I don’t have the physical nodes.
I think the problem here stems from the scene unique limitation documented here.
A scene unique node can only be retrieved by a node inside the same scene.
The player node is a scene and you are trying to get it via its unique name from another scene.
1 Like
Yeah. Funny thing is it works if I’m dragging the node into my main scene but it dosen’t work if I’m using the tilemap feature that places scenes as tiles.
I’m placing the scene (slowing) as a tile though the scene collection system whitin the tilemap layer node
Yeah i think you have to access the player differently.
why dont you use:
func _on_body_entered(body):
if body.name == "player":
body.add_effect("slow")