現在FirebaseとUnityを用いて開発をしています。
今までは.Net3.5を使っていたのですが、.Net4.xにバージョンアップしたら以下のようなエラーが起きるようになってしましました。
LoadSceneAsyncNameIndexInternal can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. UnityEngine.SceneManagement.SceneManager:LoadScene(String)
ソースコードは以下のようになっています。
C#
1public void AnonymousLogin(Action onSuccess, Action onFailed) 2 { 3 Auth.SignInAnonymouslyAsync().ContinueWith(task => 4 { 5 Debug.Log("OnAuth"); 6 if (task.IsCanceled == true) 7 { 8 Debug.LogError("Canceled"); 9 onFailed(); 10 return; 11 } 12 else if (task.IsFaulted == true) 13 { 14 Debug.LogError("Faulted"); 15 onFailed(); 16 return; 17 } 18 else if (task.IsCompleted == true) 19 { 20 Debug.Log("Completed"); 21 onSuccess(); 22 } 23 }); 24 }
C#
1public class LoginView : MonoBehaviour, ILoginView 2 { 3 public LoginPresenter _myPresenter; 4 5 private void Start() 6 { 7 _myPresenter = new LoginPresenter(this); 8 _myPresenter.DoLogin(); 9 } 10 11 public void SuccessLogin() 12 { 13 Debug.Log("isAuthOnDatabase:User name exists on database"); 14 SceneManager.LoadScene("MainScreen"); 15 } 16 17 public void NotFoundUserLogin() 18 { 19 Debug.Log("isAuthOnDatabase:User name doesn't exist on database"); 20 SceneManager.LoadScene("UserRegistration"); 21 } 22 23 } 24 25}
ViewとかPresenterとかもあるんですが、大体こんな感じにLoginメソッドを実行して、ログインが成功するとコールバックでSuccessLoginが呼ばれてMainSceneに遷移するといった感じです。
.Netのバージョンを上げる前はエラーが起きずに動作していたのですが、バージョンアップしたら上記のようなエラーが出てしまいました。ソースコードは変えてないので、何が原因なのかよくわかりません。原因や解決策について心当たりありましたら、ぜひ回答よろしくおねがいします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/07 07:20
2018/11/07 10:16