Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Discussion Best approach for Spawning in units that die a lot.

Discussion in 'Multiplayer' started by SomeVVhIteGuy, May 16, 2023.

  1. SomeVVhIteGuy

    SomeVVhIteGuy

    Joined:
    Mar 31, 2018
    Posts:
    162
    Hi there! I'm making a game which is basically an rts.

    I'm starting to spawn units for players, my first time getting so far as spawning units at runtime with the netcode framework.

    So, I'm here to ask: What is the best approach for spawning in NetworkObject units, potentially in the hundreds, that die alot and will be replaced?

    So far what I'm doing is instantiating a large pool of gameobjects when the game starts, a part of loading in. Then when a unit is needed, I SpawnWithOwnership from a list of those instantiated GO's. The issue I'm running into is when a unit dies, I don't currently have a way to find that despawned unit in the list and respawn it when needed. Before I continue down this path by adding some sort of index marker to the unit itself, I want to see if there is a better approach to this situation.
     
  2. genxium

    genxium

    Joined:
    Jun 7, 2013
    Posts:
    3
    [The links were updated to fix previously improper lookup use case.]

    I had a similar use case when I want to reuse the instances of different fireballs, and eventually decided to use a priority queue with key-value query capability
    You might also want to checkout how this solution actually works for my project here in another thread https://forum.unity.com/threads/sha...-with-some-success-in-internet-tests.1426356/
     
    Last edited: May 24, 2023