当我使用ParrelSync或多人游戏模式时,Unity 网络出现问题。
这意味着当我启动 Unity 游戏的两个窗口时, Unity Relay 和 Unity Lobby突然停止正常工作。我没有对 GameObject 的 Netcode 进行测试,因为在我开始使用它之前就会出现问题。事件过程:
两个游戏窗口以 Unity 服务中的授权开始(代码如下),并且此授权可以持续很长时间,通常会失败并重新开始。如果他们成功登录,他们会收到不同的 ID。此外,当我想在其中一个客户端上创建大厅时,创建大厅的数据交换需要很长时间,这可能会导致超时,并且在创建大厅的同时还会创建中继,但由于等待服务器响应时间较长,因此无法创建中继。一切进展顺利:
通过一个游戏窗口,一切正常。
当我尝试使用游戏的组装版本(构建和运行),从而获得两个窗口(一个在 Unity 游戏模式中,一个在构建中)时,一切都运行得很快且正确。另外:
我的代码中没有不断联系 Unity 服务器的循环;调用只发生一次,如下面的代码所示,并且不会向大厅询问有关其更新的数据。
场景开始时授权立即发生,大厅的创建由玩家发起。当两个游戏窗口进入场景并尝试登录时,问题立即出现。授权后(如果可能),问题不会消失。
我想找到一个允许使用多人游戏模式的解决方案
授权码
private async void Start()
{
try
{
await UnityServices.InitializeAsync();
AuthenticationService.Instance.SignedIn += () =>
{
Debug.Log("Singed in " + AuthenticationService.Instance.PlayerId);
};
await AuthenticationService.Instance.SignInAnonymouslyAsync();
playerName = "Player(" + Random.Range(0, 10) + ")";
}
catch (AuthenticationException ex)
{
Debug.LogError(ex);
}
}
授权日志
[Authentication]: Network error detected, retrying...
0x00007ffcef4d6bdd (Unity) StackWalker::ShowCallstack
0x00007ffcef4e6b99 (Unity) PlatformStacktrace::GetStacktrace
0x00007ffcf075132e (Unity) Stacktrace::GetStacktrace
0x00007ffcf0cf9cbf (Unity) DebugStringToFile
0x00007ffcee603575 (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x0000015777a6db2d (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log_Injected (UnityEngine.LogType,UnityEngine.LogOption,UnityEngine.Bindings.ManagedSpanWrapper&,intptr)
0x0000015777a6d9f3 (Mono JIT Code) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x0000015777a6d62b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
0x000001583ecdab7d (Mono JIT Code) UnityEngine.Logger:LogWarning (string,object)
0x000001583ecdaa3d (Mono JIT Code) Unity.Services.Authentication.Logger:LogWarning (object) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Utilities/Logger.cs:17)
0x000001583ecda803 (Mono JIT Code) Unity.Services.Authentication.WebRequest:RequestCompleted (System.Threading.Tasks.TaskCompletionSource`1<string>,long,bool,bool,string,string,System.Collections.Generic.IDictionary`2<string, string>) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:182)
0x000001583ecd90c3 (Mono JIT Code) Unity.Services.Authentication.WebRequest/<>c__DisplayClass16_0:<SendAttemptAsync>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:83)
0x000001583ecd8f1b (Mono JIT Code) UnityEngine.AsyncOperation:InvokeCompletionEvent ()
0x000001584942ef08 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffcf408699e (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ffcf3fc8444 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3068)
0x00007ffcf3fc8530 (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3115)
0x00007ffcef3fabf4 (Unity) scripting_method_invoke
0x00007ffcef3d2983 (Unity) ScriptingInvocation::Invoke
0x00007ffcef3cdc45 (Unity) ScriptingInvocation::Invoke<void>
0x00007ffcef56b509 (Unity) Scripting::UnityEngine::AsyncOperationProxy::InvokeCompletionEvent
0x00007ffcef06c758 (Unity) AsyncOperation::InvokeCoroutine
0x00007ffcefac0f8c (Unity) UnityWebRequestAsyncOperation::InvokeCoroutine
0x00007ffcefac1181 (Unity) UnityWebRequestProto<UnityWebRequestTransport,AtomicRefCounter,RedirectHelper,ResponseHelper,DownloadHandler,UploadHandler,CertificateHandler,HeaderHelper,AsyncOperation>::Job_InvokeCoroutine
0x00007ffceefeabaa (Unity) BackgroundJobQueue::ExecuteMainThreadJobs
0x00007ffcef078cbc (Unity) `InitPlayerLoopCallbacks'::`2'::EarlyUpdateExecuteMainThreadJobsRegistrator::Forward
0x00007ffcef047fc7 (Unity) ExecutePlayerLoop
0x00007ffcef048137 (Unity) ExecutePlayerLoop
0x00007ffcef04d26f (Unity) PlayerLoop
0x00007ffcf014f22a (Unity) EditorPlayerLoop::Execute
0x00007ffcf0165be7 (Unity) PlayerLoopController::InternalUpdateScene
0x00007ffcf016799d (Unity) PlayerLoopController::UpdateSceneIfNeededFromMainLoop
0x00007ffcf0161751 (Unity) Application::TickTimer
0x00007ffcf075603a (Unity) MainMessageLoop
0x00007ffcf075bd12 (Unity) UnityMain
0x00007ff78e092fba (Unity) __scrt_common_main_seh
0x00007ffd5de47374 (KERNEL32) BaseThreadInitThunk
0x00007ffd5f09cc91 (ntdll) RtlUserThreadStart