I'm in the process of migrating a game to PlayerIO hosted multiplayer. To that effect, things previously stored in ScriptableObjects need to be moved onto BigDB. To do that, I added an button to the ScriptableObject's inspector which is meant to store the SO's values in BigDB, and an editor extension to authenticate and provide that Client instance to other editor scripts.
It seems this use case was not considered, though, since authenticating from an editor script causes the following exception:
- Code: Select all
InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: PlayerIO-b1f207b6edc84cd8ac6e72876efc1d75. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script.
__PlayerIO_UnityInterop.Get () (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.Internal.identifier1036.Get () (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.Internal.identifier49.startUnityMessagePump () (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.Internal.identifier49.Enqueue (System.Collections.IEnumerator enumerator) (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.Internal.identifier126+identifier828.Call[A,O,E] (System.Int32 method, A args, PlayerIOClient.Callback`1[T] success, PlayerIOClient.Callback`1[T] error) (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.PlayerIO+ChannelMonitor.Call[A,O,E] (System.Int32 methodId, A args, PlayerIOClient.Callback`1[T] success, PlayerIOClient.Callback`1[T] error) (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.Internal.identifier126.Authenticate (System.String gameId, System.String connectionId, System.Collections.Generic.Dictionary`2[TKey,TValue] authenticationArguments, System.Collections.Generic.List`1[T] playerInsightSegments, System.String clientAPI, System.Collections.Generic.Dictionary`2[TKey,TValue] clientInfo, System.Collections.Generic.List`1[T] playCodes, PlayerIOClient.Callback`1[T] onSuccess, PlayerIOClient.Callback`1[T] onError) (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.PlayerIO+<>c__DisplayClass13.<Authenticate>b__f () (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.PlayerIO.ensureInitialized (PlayerIOClient.Callback callback) (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOClient.PlayerIO.Authenticate (System.String gameId, System.String connectionId, System.Collections.Generic.Dictionary`2[TKey,TValue] authenticationArguments, System.String[] playerInsightSegments, PlayerIOClient.Callback`1[T] successCallback, PlayerIOClient.Callback`1[T] errorCallback) (at <845ea6bf4ddb4435a4783693c560680c>:0)
PlayerIOWindow.OnGUI () (at Assets/Scripts/Editor/PlayerIOWindow.cs:29)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:305)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:313)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:272)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:265)
UnityEditor.HostView.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:94)
This could be fixed rather trivially on your end by checking Application.isEditor before calling DontDestroyOnLoad.