问题:SceneManager.LoadScene之后调用SceneManager.SetActiveScene报错,提示场景未加载。(ArgumentException: SceneManager.SetActiveScene failed; scene 'XXX' is not loaded and therefore cannot be set active)
原因:SceneManager.LoadScene
Unity5.x
这个函数调用后马上加载场景
Unity2017.x
这个函数调用后第二帧结束的时候完成加载
2017/2018的文档说明:“When using SceneManager.LoadScene, the loading does not happen immediately, it completes in the next frame. This semi-asynchronous behavior can cause frame stuttering and can be confusing because load does not complete immediately.”
解决办法:
在SceneManager.LoadScene调用之后添加2个 yield return new WaitForEndOfFrame(); 就OK了。
PS:Unity5.x无此问题