Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | BradColbert |
I had this structure in order a sprite to follow a created path
Path2d
PathFollow2d
Sprite
then i replaced the Sprite node with Enemy node which is a scene containing
Area2d
Sprite
CollisionShape2d
In my root scene i created instance of path2d scene. everything works as enemy is following the path properly. At some point of the path i need to call some method (eg. shoot) of the Enemy scene but the engine says that this method doesnt exists.
turns out that none of the methods of Enemy.tscn are called (eg. _ready() … etc)
im getting the node in my path2d scene like that
onready var enemy = get_node("PathFollow2d/Enemy")
but cant call any methods on enemy as i said
Printing enemy object in _ready function of Path2d says its Area2d, so its not null
Also, if i drop the Enemy.tscn in the viewport (in my main scene), the init methods are called, but not sure why this doesnt work if Enemy scene is a child of that path2d/pathfollow2d
Do you add enemy as a child of path
add_child(enemy)
Also check if the any you instance have a script
code | 2021-03-02 22:26