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.
  2. Dismiss Notice

Question Destroying and Respawning an Agent

Discussion in 'ML-Agents' started by spacestar1705, Aug 16, 2023.

  1. spacestar1705

    spacestar1705

    Joined:
    May 2, 2022
    Posts:
    13
    Hi, I am trying to create a space shooter game and this is only my second game in unity. I am still trying to figure things out. Please help me with this.

    I have a spaceship prefab that comes loaded with missiles. Now, when I shoot at the target (just one for now), the episode needs to end and in the new episode the spaceship should have all the missiles. Currently, because I don't know how destroying and spawning an agent works, I am just setting the agent gameobject active and inactive when the episodes begin or end. The problem with this is that the missiles are not loaded back at the beginning of the episode.

    Can someone please give me pointers on how I can destroy and spawn a new agent so that it has all the missiles when a new episode begins?

    Thanks in advance :)
     
  2. Energymover

    Energymover

    Joined:
    Mar 28, 2023
    Posts:
    29
    Sounds like you just need to override the OnEpisodeBegin and reload some missiles for each of the agents.

    Destroy and spawn of agents is no different than any other game object, just that these game objects have an agent script attached to them. Enable and disable works the same way, no real difference, other than possibly overhead of "recreating" an object vs. "enabling" of an object with enabling possibly being less overhead.