I’m doing this in Unreal Engine 5, but how this is done should be relevant for any engine, minus the details of spawning and despawning.

Anybody know how large games handle spawning and despawning enemies? One idea I had was to have a really large sphere around the player that spawns enemies when the player overlaps spawn points. But that could get tricky to implement. Another idea I had was to spawn enemies as the player enters different areas, and just put them to sleep/deactivate them until the overlap a large player sphere.

Would love to know other people’s thoughts on this. I’m looking for something that has good performance and scalability. I’m going to start testing ideas soon. But would be great if someone already knew of a solution that works.

Edit: Why downvote? I’m asking for discussion on algorithms. Is that not the point of this community…

  • Mac@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    I dont know how larger games do it but it mostly depends on what kinds of enemies and what genre of game youre doing.

    If you have a lot of enemies that will be spawned and despawned and they are mostly the same you can do an object pool where instead of destroying the object it gets hidden and added to the back of the pool for another enemy to spawn in as in the future by showing it and moving it to the correct spot

    In terms of when to spawn it usually (assuming youre doing most genres) you can just spawn it right outside the view of the player when they hit a trigger. In games I usually make enemies are spawned on a timer since it tends to be more arcade like and in that case you usually just spawn them outside the range of the player in a random location around a radius after X amount of time has passed

    Can give more specific things if I know the genre

    Also downvote is likely someone from the all feed

    • NocturnalMorning@lemmy.worldOP
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      9 months ago

      It’s an rpg/soulslike, so I wouldn’t likely be spawning randomly all the time. But I do like the idea of spawning in a small radius outside the player view, and the pool idea is good. That could really help with keeping resources down. Only issue I could see with that is distinguishing which pool actors to choose the activate again. I’ll have to think about that a little bit since enemies will be different.