Ml-agents: Crash after reloading the scene

Created on 20 Dec 2018  路  6Comments  路  Source: Unity-Technologies/ml-agents

Getting the following error since I migrated to 0.6. It happens when reloading the scene with SceneManager.LoadScene in Play mode (using my test scene basically). This was not happening with 0.5

ArgumentException: An item with the same key has already been added. Key: OpponentAI (OpponentAI) System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at :0)
System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) (at <ac823e2bb42b41bda67924a45a0173c3>:0) MLAgents.Brain.SendState (MLAgents.Agent agent, MLAgents.AgentInfo info) (at Assets/ML-Agents/Scripts/Brain.cs:56) MLAgents.Agent.SendInfoToBrain () (at Assets/ML-Agents/Scripts/Agent.cs:619) MLAgents.Agent.SendInfo () (at Assets/ML-Agents/Scripts/Agent.cs:984) MLAgents.Academy.EnvironmentStep () (at Assets/ML-Agents/Scripts/Academy.cs:583) MLAgents.Academy.FixedUpdate () (at Assets/ML-Agents/Scripts/Academy.cs:611)

It seems related to line 56 in Brain.cs:
agentInfos.Add(agent, info);

I tried to add a ContainsKey() check and the error went away but the agent is then not taking any action.

Any idea?

bug

Most helpful comment

Hi @13Flo,

Thanks for pointing this out. We will add it to our bug list, and look into it soon.

All 6 comments

Hi @13Flo,

Thanks for pointing this out. We will add it to our bug list, and look into it soon.

I have the same problem (only on 0.6), when i spawn my AIs on the first scene it works fine.

When i spawn them after changing scene:

ArgumentException: An item with the same key has already been added. Key

peek 2018-12-24 15-01

Same issue here! (ml-agents 0.6)

The error An item with the same key has already been added. is symptomatic of an error that occurred earlier in the process. My guess is that when reloading the scene, a second academy was instantiated which broke the connection to the agents in the scene. There is a patch to this bug in v0.8. You can also set the academy game object to don't destroy on load.

Since there is fix in v0.8, we are closing this.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings