Unity-Technologies/ml-agents · error · UnityAgentsException

Call to SendInfoToBrain when Agent hasn't been initialized.P

Error message

Call to SendInfoToBrain when Agent hasn't been initialized.Please ensure that you are calling 'base.OnEnable()' if you have overridden OnEnable.

What it means

Agent.SendInfoToBrain throws UnityAgentsException when the agent's m_Initialized flag is false, meaning the agent's OnEnable/Initialize chain never ran before brain communication was attempted. The message points at the usual culprit: overriding OnEnable without calling base.OnEnable().

Source

Thrown at com.unity.ml-agents/Runtime/Agent.cs:1096

            m_VectorActuator = new AgentVectorActuator(this, this, param.ActionSpec);
            m_ActuatorManager = new ActuatorManager(attachedActuators.Length + 1);

            m_ActuatorManager.Add(m_VectorActuator);

            foreach (var actuatorComponent in attachedActuators)
            {
                m_ActuatorManager.AddActuators(actuatorComponent.CreateActuators());
            }
        }

        /// <summary>
        /// Sends the Agent info to the linked Brain.
        /// </summary>
        void SendInfoToBrain()
        {
            if (!m_Initialized)
            {
                throw new UnityAgentsException("Call to SendInfoToBrain when Agent hasn't been initialized." +
                    "Please ensure that you are calling 'base.OnEnable()' if you have overridden OnEnable.");
            }

            if (m_Brain == null)
            {
                return;
            }

            if (m_Info.done)
            {
                m_Info.ClearActions();
            }
            else
            {
                m_Info.CopyActions(m_ActuatorManager.StoredActions);
            }

            UpdateSensors();

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Add base.OnEnable() at the start of any OnEnable() override in your Agent subclass
  2. Ensure decisions are only requested after the agent is initialized (e.g. in OnEpisodeBegin or later)
  3. Check that the agent is properly initialized by the Academy before calling SendInfoToBrain-dependent paths

Example fix

// before
void OnEnable() { InitMyStuff(); }
// after
void OnEnable() { base.OnEnable(); InitMyStuff(); }
Defensive patterns

Strategy: validation

Validate before calling

if (!agent.Initialized) {
    Debug.LogError("Agent not initialized; ensure base.OnEnable() is called.");
} else {
    agent.SendInfoToBrain();
}

Type guard

bool IsReady(Agent a) => a != null && a.Initialized;

Try / catch

try { RequestDecision(); } catch (UnityAgentsException e) { Debug.LogError(e.Message); }

Prevention

When it happens

Trigger: Overriding OnEnable() (or OnBeforeFatalHidden etc.) in an Agent subclass without calling base.OnEnable(), so the agent is never initialized; sending decisions before initialization completes.

Common situations: Subclassed agents with custom OnEnable logic; requesting a decision in Start or externally before the Academy initialized the agent; disabling/enabling scripts whose overrides skip base calls.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/612eea933b74f161. Report an issue: GitHub.