setting new path affect ALL instanced enemies rather than only one. why ?

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

ahhhhhh i’m stuck.

First time encountering this.
I instance some enemies > when my projectile hit they do all sort of things :

  • slow them down.
  • apply damage
  • apply damage over time
    etc… All this works perfectly. it only affect the body the projectile has touched.

But. When i want to make a projectile that make the enemy walk back to it starting point with get_simple_path, ALL the enemies turn around instead of only the one i hit.

The process is the same for ALL the other effect projectile does. But this one is problematic…
Any idea why ? is there a work around it ?

Here is my code :
enemy.gd which i instance:

Header part :

var path : = PoolVector2Array() setget set_path

Rest :
var nav_send_back = get_node(“/root/MAIN_MAP/Nav/”)
var nav_send_back_position = get_node(“/root/MAIN_MAP/start_position”)
var path_send_back = nav_send_back.get_simple_path(self.position, nav_send_back_position.position) # we calculate their new path if any.

	set_path(path_send_back)

so when ever i update the path… it affect ALL instanced enemies. not just this one…
Any idea why ? thanks guys !

if anyone read this… i’m still stuck on this :confused:

quizzcode | 2020-05-24 10:26

The process is the same for ALL the other effect projectile does.

Except that all the other effects (judging from the examples you gave at least) do not change the enemies path, isn’t it?

so when ever i update the path… it affect ALL instanced enemies.

Odd. From the code you provided it’s neither obvious what happens when a projectile is colliding with an enemy nor what set_path does though. The portion of the script you posted looks fine. However, it would be a lot easier to read if you would take the time to format it properly: all lines of code need to be indented by at least 4 spaces or underscores will be treated as markdown-elements.

Consider providing an example project if you can.

njamster | 2020-05-24 13:09

How do you instance your enemies?

A112Studio | 2020-05-24 15:05

get_node("/root/MAINMAP/Nav/") doesn’t need to end with a “/” I’m surprised that didn’t cause an error.

Magso | 2020-05-24 16:18

get_node(“/root/MAINMAP/Nav/”) doesn’t need to end with a “/” I’m surprised that didn’t cause an error.

Good catch! It didn’t cause an error, because it isn’t one: while the slash in the end is not necessary, it won’t break anything either. Actually, "/root//MAINMAP///NAV////" would work as well. Nevertheless that’s not the issue here, as quizzcode’s script works. The problem is that it apparently works for all instances, not just one.

njamster | 2020-05-24 18:02

Thank you so much for all your answer. Always appreciate it !

quizzcode | 2020-05-24 18:08

Ehhm so this is awkward.
I always post the solution to my question as soon as i find it in case someone is looking for similar problems.

But this time, I have no idea why… but it’s working. And I have no clue what changed.
I did mess around with the script without paying too much attention yesterday as i was over it. And somehow it’s working.

So… Thank you everyone regardless.
And if i can reproduce the error i will post the “change”.

Appreciate your help.

quizzcode | 2020-05-24 18:13