浏览代码

Fix for Brains not reinitialising when the scene is reloaded. (#1758)

* Fix for Brains not reinitialising when the scene is reloaded.

This was a bug caused by the conversion of Brains over to ScriptableObjects. ScriptableObjects persist in memory between scene changes, which means that after a scene change the Brains would still be initialised and the agentInfos list would contain invalid references to the Agents from the previous scene.

The fix is to have the Academy notify the Brains when it is destroyed. This allows the Brains to clean themselves up and transition back to an uninitialised state. After the new scene is loaded, the Brain's LazyInitialise will reconnect the Brain to the new Academy as expected.

* Fix for Brains not reinitialising when the scene is reloaded.

This was a bug caused by the conversion of Brains over to ScriptableObjects. ScriptableObjects persist in memory between scene changes, which means that after a scene change the Brains would still be...
/develop-generalizationTraining-TrainerController
Vincent-Pierre BERGES 6 年前
当前提交
9b00c012
共有 2 个文件被更改,包括 29 次插入3 次删除
  1. 7
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
  2. 25
      UnitySDK/Assets/ML-Agents/Scripts/Brain.cs

7
UnitySDK/Assets/ML-Agents/Scripts/Academy.cs


// actions for their agents.
public event System.Action BrainDecideAction;
// Signals to all the listeners that the academy is being destroyed
public event System.Action DestroyAction;
// Signals to all the agents at each environment step along with the
// Academy's maxStepReached, done and stepCount values. The agents rely
// on this event to update their own values of max step reached and done

isInference = !isCommunicatorOn;
BrainDecideAction += () => { };
DestroyAction += () => { };
AgentSetStatus += (m, d, i) => { };
AgentResetIfDone += () => { };
AgentSendState += () => { };

Physics.gravity = originalGravity;
Time.fixedDeltaTime = originalFixedDeltaTime;
Time.maximumDeltaTime = originalMaximumDeltaTime;
// Signal to listeners that the academy is being destroyed now
DestroyAction();
}
}
}

25
UnitySDK/Assets/ML-Agents/Scripts/Brain.cs


{
if (!_isInitialized)
{
FindObjectOfType<Academy>().BrainDecideAction += BrainDecideAction;
Initialize();
_isInitialized = true;
var academy = FindObjectOfType<Academy>();
if (academy)
{
academy.BrainDecideAction += BrainDecideAction;
academy.DestroyAction += Shutdown;
Initialize();
_isInitialized = true;
}
/// <summary>
/// Called by the Academy when it shuts down. This ensures that the Brain cleans up properly
/// after scene changes.
/// </summary>
private void Shutdown()
{
if (_isInitialized)
{
agentInfos.Clear();
_isInitialized = false;
}
}
/// <summary>
/// Calls the DecideAction method that the concrete brain implements.
/// </summary>

正在加载...
取消
保存