Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Connect New Agent After Training Has Started

Discussion in 'ML-Agents' started by Ch1ckenNug, May 8, 2023.

  1. Ch1ckenNug


    Sep 14, 2021
    So I am instantiating my agent from another script after the training has already started. However, this brain is not connecting to Python, and does not train. Is there any way for me to connect the agent to the Python from a C# script?. And no, in the situation I am in, it is not possible to load the scene with the agent already created. Below is how I am instantiating the agent, if it helps.
    Code (CSharp):
    1. GameObject seekerObject = Instantiate(seekerPrefab, new Vector3(0, 0, 0.5f), Quaternion.identity);
    2. seekerObject.transform.SetParent(transform);
    3. AgentScript agentScript = seekerObject.GetComponent<AgentScript>();
    4. agentScript.Initialize();
    5. seekerObject.GetComponent<Unit>().target = targetObject.transform;
    6. seekerObject.SetActive(true);
  2. Luke-Houlihan


    Jun 26, 2007
    You should be able to train with agents spawned at runtime just fine, can you add some more detail about how your instantiating/ the use case?

    Not sure about this but have you tried activating the gameobject `seekerObject` before running Initialize? Sometimes components on disabled gameobjects behave strangely (for example coroutines wont run on a disabled gameobject). Might be worth a try.