Ive been using NetworkManager.SceneManager.OnLoadEventCompleted, but this is not reliable, as this only fires on the Server/Host. I load a new scene and then need to load data for players that exists only in that scene. For example I connect to a lobby, switch scene, and then need to generate a UI for the Inventory that didnt exist before. I tried using Awake/Start as well but nothing seems to work, I just cant reliably get something running when a scene is loaded
#How to reliably know when a scene is loaded?
1 messages · Page 1 of 1 (latest)
maybe just the standard unity callback? https://docs.unity3d.com/6000.3/Documentation/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html
will fire on each client of course
This does not get fired on a client at all. I implemented it the same way as in the docs, add the event in OnEnable, and log in the event method. It never gets calles. Actually, OnEnabled does run, but OnSceneLoaded never does. There is nothing loggign OnSceneLoaded: ...In the console, except for the server, which works fine. But thats not what I need, I need the client
show code?
void OnEnable()
{
Debug.Log("OnEnable called");
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnDisable()
{
Debug.Log("OnDisable");
SceneManager.sceneLoaded -= OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
Debug.Log("OnSceneLoaded: " + scene.name);
Debug.Log(mode);
}
SceneLoaded runs before any objects in the scene get any messages
You would subscribe to sceneloaded on something before the scene is loaded
LoadEventCompleted will fire on the clients
https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.7/manual/basics/scenemanagement/scene-events.html#when-are-load-or-unload-sceneevents-truly-complete
Is this in the original scene or the new scene? Clients might be subscribing too late
Its the new scene on the server, its before a scene loads on the client I believe, but because it doesnt "load" the scene but rather "syncs" it I think it never actually counts as a scene transtiton, I did find a super hacky way to do what I need tho