-
Notifications
You must be signed in to change notification settings - Fork 446
Can use Don't destroy on load on in scene networkObjects #3402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This error is most likely due to the fact that when you are ending your session you are not destroying the It might be you have something like:
To avoid this issue, you will want to have your The other approach (since it is persisting throughout your session) is to do something like this: public class PlayerDataManager : NetworkBehaviour
{
public PlayerDataManager Instance;
public bool DestroyNewInstance;
private void Awake()
{
if (Instance != null && Instance.gameObject != gameObject)
{
if (!DestroyNewInstance)
{
// Destroys the last instance
Destroy(Instance.gameObject);
}
else
{
// Preserves the original/first instance
Destroy(gameObject);
}
}
Instance = this;
}
private void Start()
{
DontDestroyOnLoad(gameObject);
}
} Let me know if this resolves your issue? |
The problem occurs even if i reboot both Unity and my PC, so i think the "not destroying properly the manager" part is not the source of the problem My scene layout is, for the moment, way simpler : A "Main Menu" scene handling connection and lobby, a "Main Game" scene handling the game itself I tried your fix on my singleton parent class, the DDOL part does not throw an error anymore but when a client tries to join the session (when creating, it's fine) a warning and an error are thrown : Warning : Error : And when i try to access a NetworkList in the PlayerDataManager it throws an error : |
Hi @Urganway, My apologies on the script as the To avoid making another mistake, I am attaching a replication project that is close to your setup (minus the lobby) that includes the above I am also including a small video to show it working: InSceneDDOL.mp4Take a look at the video and the project I provided and see if this helps you resolve/find the issue in your project? |
Is your feature request related to a problem? Please describe.
I'm trying to make a persistent Manager object in my game using single scenes but the DontDestroyOnLoad Method does not work as the documentation suggests here :
Instead it throw this error :
Exception: PlayerDataManager tried to registered with ScenePlacedObjects which already contains the same GlobalObjectIdHash value 281576103 for PlayerDataManager! Unity.Netcode.NetworkSceneManager.PopulateScenePlacedObjects (UnityEngine.SceneManagement.Scene sceneToFilterBy, System.Boolean clearScenePlacedObjects) (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/SceneManagement/NetworkSceneManager.cs:2835) Unity.Netcode.NetworkSpawnManager.ServerSpawnSceneObjectsOnStartSweep () (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Spawning/NetworkSpawnManager.cs:1457) Unity.Netcode.NetworkManager.HostServerInitialize () (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkManager.cs:1523) Unity.Netcode.NetworkManager.StartHost () (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkManager.cs:1474) UnityEngine.Debug:LogException(Exception) Unity.Netcode.NetworkManager:StartHost() (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkManager.cs:1479) Unity.Services.Multiplayer.GameObjectsNetcodeNetworkHandler:StartAsHost() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Multiplayer/Modules/Connection/Handlers/Connection/GameObjectsNetcodeNetworkHandler.cs:174) Unity.Services.Multiplayer.GameObjectsNetcodeNetworkHandler:SetupRelay(NetworkConfiguration) (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Multiplayer/Modules/Connection/Handlers/Connection/GameObjectsNetcodeNetworkHandler.cs:113) Unity.Services.Multiplayer.GameObjectsNetcodeNetworkHandler:StartAsync(NetworkConfiguration) (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Multiplayer/Modules/Connection/Handlers/Connection/GameObjectsNetcodeNetworkHandler.cs:26) Unity.Services.Multiplayer.<SetupConnectionAsync>d__31:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Multiplayer/Modules/Connection/ConnectionModule.cs:315) System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(<SetupConnectionAsync>d__31&) Unity.Services.Multiplayer.ConnectionModule:SetupConnectionAsync(NetworkConfiguration) Unity.Services.Multiplayer.<CreateConnectionAsync>d__26:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Multiplayer/Modules/Connection/ConnectionModule.cs:138) System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult() Unity.Services.Multiplayer.<FetchJoinCodeAsync>d__18:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Multiplayer/Modules/Connection/Handlers/Relay/RelayHandler.cs:106) System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:SetResult(String)Unity.Services.Relay.d__11:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/SDK/WrappedRelayService.cs:134)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:SetResult(Response
1)Unity.Services.Relay.Apis.RelayAllocations.d__8:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/Apis/RelayAllocationsApi.cs:160)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:SetResult(HttpClientResponse) Unity.Services.Relay.Http.<MakeRequestAsync>d__1:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/Http/HttpClient.cs:41) System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:SetResult(HttpClientResponse)Unity.Services.Relay.Http.d__3:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/Http/HttpClient.cs:56)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:SetResult(HttpClientResponse) Unity.Services.Relay.Http.<CreateHttpClientResponse>d__4:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/Http/HttpClient.cs:84) System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:SetResult(HttpClientResponse)Unity.Services.Relay.Http.<b__0>d:MoveNext() (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/Http/HttpClient.cs:81)
System.Threading.Tasks.TaskCompletionSource
1:SetResult(HttpClientResponse) Unity.Services.Relay.Http.<>c__DisplayClass0_0:<GetAwaiter>b__0(AsyncOperation) (at ./Library/PackageCache/com.unity.services.multiplayer@124598b145d4/Runtime/Relay/Http/UnityWebRequestHelpers.cs:34) UnityEngine.AsyncOperation:InvokeCompletionEvent()
Describe the solution you'd like
Either DontDestroyOnLoad can be called on in-scene NetworkObjects without error
Or Update the documentation to not tell it works this way and propose a suitable solution for Netcode Managers
Describe alternatives you've considered
I'm currently spawning my manager as suggested for the "hybrid approach", which works, but this feels not right for this purpose since in the doc it says that i can have my netcode manager as an in-scene object and the "hybride approch" is not for this purpose specificaly.
Additional context
The Manager is a PlayerDataManager which spawns, stores and gives access to playerData components which contains elements needed in both Menu and Game scenes (and can't be separated)
The text was updated successfully, but these errors were encountered: