Spawning unique enemies

HanskHansk Posts: 6Member

Hello, I am working on a 3d FPS type shooter and I am running into a small issue when it comes to my enemies. Currently I have a basic enemy that will look at, then follow the player while "shooting" at it printing "hit." I also have a line of code that finds the Body mesh of the enemy and changes the albedo from green to red to give a visual indicator that the enemy sees the player and is running the proper code. Additionally, I have a signal emitting from the player's weapon script when a raycast is emitted and collides into anything within the group "Enemies", which the enemy is in, and outputs "enemy damaged."

My issue seems to be that Godot doesn't distinguish between the two Enemy scrips when running the code. If the player walks into the view of Enemy1, both enemies will turn red even though only Enemy1 goes into the alert state and follows the player. Also, when the player shoots at the enemy the output will printout two lines of "enemy damaged." It appears that since both enemies have the name "Enemy" with a mesh named "Body" the script will bring up both when they are called even though they are separate instances. I need to make them each unique but I haven't been able to find a way to do it that doesn't involve giving every enemy in the game a unique name, which seems silly.

Anyone have any pointers?


  • MegalomaniakMegalomaniak Posts: 2,740Admin

    I would start by looking at the remote scene tree in the editor while the game runtime is running(after launching it from the editor). I'm guessing you aren't spawning/instancing the nodes with unique names.

  • HanskHansk Posts: 6Member

    They are named as I renamed them in the normal node tree: Enemy1, and Enemy2. I've seen examples where Godot will give them names like "@enemy@1, @enemy@2, @enemy@3, etc" but I haven't figured out how to do that yet.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file