{"record":{"id":"612eea933b74f161","repo":"Unity-Technologies/ml-agents","slug":"call-to-sendinfotobrain-when-agent-hasn-t-been-ini","errorCode":null,"errorMessage":"Call to SendInfoToBrain when Agent hasn't been initialized.Please ensure that you are calling 'base.OnEnable()' if you have overridden OnEnable.","messagePattern":"Call to SendInfoToBrain when Agent hasn't been initialized\\.Please ensure that you are calling 'base\\.OnEnable\\(\\)' if you have overridden OnEnable\\.","errorType":"exception","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Agent.cs","lineNumber":1096,"sourceCode":"            m_VectorActuator = new AgentVectorActuator(this, this, param.ActionSpec);\n            m_ActuatorManager = new ActuatorManager(attachedActuators.Length + 1);\n\n            m_ActuatorManager.Add(m_VectorActuator);\n\n            foreach (var actuatorComponent in attachedActuators)\n            {\n                m_ActuatorManager.AddActuators(actuatorComponent.CreateActuators());\n            }\n        }\n\n        /// <summary>\n        /// Sends the Agent info to the linked Brain.\n        /// </summary>\n        void SendInfoToBrain()\n        {\n            if (!m_Initialized)\n            {\n                throw new UnityAgentsException(\"Call to SendInfoToBrain when Agent hasn't been initialized.\" +\n                    \"Please ensure that you are calling 'base.OnEnable()' if you have overridden OnEnable.\");\n            }\n\n            if (m_Brain == null)\n            {\n                return;\n            }\n\n            if (m_Info.done)\n            {\n                m_Info.ClearActions();\n            }\n            else\n            {\n                m_Info.CopyActions(m_ActuatorManager.StoredActions);\n            }\n\n            UpdateSensors();","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Agent.cs#L1078-L1114","documentation":"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().","triggerScenarios":"Overriding OnEnable() (or OnBeforeFatalHidden etc.) in an Agent subclass without calling base.OnEnable(), so the agent is never initialized; sending decisions before initialization completes.","commonSituations":"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.","solutions":["Add base.OnEnable() at the start of any OnEnable() override in your Agent subclass","Ensure decisions are only requested after the agent is initialized (e.g. in OnEpisodeBegin or later)","Check that the agent is properly initialized by the Academy before calling SendInfoToBrain-dependent paths"],"exampleFix":"// before\nvoid OnEnable() { InitMyStuff(); }\n// after\nvoid OnEnable() { base.OnEnable(); InitMyStuff(); }","handlingStrategy":"validation","validationCode":"if (!agent.Initialized) {\n    Debug.LogError(\"Agent not initialized; ensure base.OnEnable() is called.\");\n} else {\n    agent.SendInfoToBrain();\n}","typeGuard":"bool IsReady(Agent a) => a != null && a.Initialized;","tryCatchPattern":"try { RequestDecision(); } catch (UnityAgentsException e) { Debug.LogError(e.Message); }","preventionTips":["Always call base.OnEnable() when overriding OnEnable in Agent subclasses","Request decisions only after OnEpisodeBegin / Academy init","Check m_Initialized (Initialized) before brain interaction"],"tags":["unity","ml-agents","agent","initialization-order"],"backgroundTag":"uninitialized-object-usage","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}