+1 vote

My primary game scene contains several instanced enemies placed on the scene (not programmatically). These enemies have an Area2D child which is used detect when the player comes close enough to them to follow and attack.

This worked perfectly fine with the original way I was changing scenes:

var main = main_scene.instance()
get_tree().change_scene_to(main)

I wanted to get a little more control over my scenes and recently changed this code:

var main = main_scene.instance()
get_tree().get_root().add_child(main)
get_tree().get_root().get_node("Lobby").hide()

The level and enemies appear like normal, but the instanced enemies have stopped following and attacking the player.

Is there some sort of additional set up I need to do to ensure the main scene's children continue to function?

asked Jul 5 in Engine by brandogs (20 points)

Hi ,
Do you have a scene for the enemies and the new level inherited these nodes ?
Check the parameters are the same , if you have the code somewhere share do we can have a look ( layers and masks)
Good luck

Hi Jorge,
I have a few different separate scenes that extend each other for the characters. For example, zombie.gd and mummy.gd both extend a basic enemy.gd to add unique abilities to these enemy types. Enemy.gd contains the universal functions and child nodes, such as an Area2Ds for player detection, an Area2D for hit collision, etc.

The main game scene is a collection of other instanced scenes inherited from other files, such as level.tscn, gui.tscn, and several enemies from zombie.tscn and mummy.tscn. The player's character is being added programmatically, since I plan to allow multiple different character classes.

The player is still able to interact with the enemy mobs, hitting and killing them off enemies. It's just the enemies themselves do not act on their own anymore (chasing players or attacking when the player is near) after changing the scenes transition from the lobby the the main game scene.

I don't think this should be a layer or mask configuration issue, as I can switch the scene transition back to get_tree().change_scene_to(main) and all of my enemies start chasing the player and attacking them again.

Please log in or register to answer this question.

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.