How do I activate an inactive enemy when I go near her?

I’m making an RPG game and there are a lot of enemies in the game and for optimization I want them to pop up when I go near them. However, since the object is not active, I can neither measure its distance with my character nor detect and open it with collider. What advice would you give me for this problem?

Make sure you actually need this optimization or else you’re just making a complicated mess of your program.

I would just leave them all on all the time.

Otherwise, leave some script on somewhere that watches the player and wakes up a particular enemy.

Alternately, make enemies have a sub-portion that can be turned off to make them go away, and a base portion that stays on:

EverythingElseInTheEnemyThatGetsTurnedOff```

I tend to make a “spawn point” object for each enemy or a group of enemies. It’s an invisible object with no mesh. but handles when to create enemy objects based on a OnTriggerEnter or distance check.

The advantage making a separate object from the actual enemy is that you can also use this object to handle re-spawn logic. For example, after all of the original enemies have been destroyed then maybe it won’t spawn new enemies again until a certain amount of time has passed or something like that.

1 Like

I’m making an RPG game and there are more than 2000 enemies in the game. When all of them are unlocked, the game gets stuck a lot. The game works better with the second method you suggested.

Thank you, I am trying the method you mentioned now. I will write when I finish.

In alternative version you can just make invisible trigger object around own character (don’t has to be around each enemy). So if trigger bump enemy you tell them to activate. Trigger for each enemy will be better if you plan to have different trigger range.

I divided the enemies into groups of 10 and 15, and managed their opening and closing through parenting. When I do this individually, while measuring the distance, the computer was running slowly. It worked better in group form.