Manual Scene Transition Breaks Instanced Enemies

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By brandogs

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()

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

var main = main_scene.instance()

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?

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

Jorge | 2020-07-05 09:01

Hi Jorge,
I have a few different separate scenes that extend each other for the characters. For example, and both extend a basic to add unique abilities to these enemy types. 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.

brandogs | 2020-07-05 18:20