#Move a connection to an existing stacked scene?

10 messages · Page 1 of 1 (latest)

prisma ridge
#

hi, all.

is there an API to get the connection scene that has just been loaded with scene stacking for one or more network connections?

I'm loading connection scenes with scene stacking and move connections following scene loader example, so now I want to get a scene that was loaded at some point for a new connection to move to but problem is, I can't seem to find an easy way to go about doing it.

I have checked SceneManager.OnLoadEnd, SceneManager.OnClientPresenceChanged events however, I could only get to confuse even more due to my own lack of experience with FN of course.

is there an easy way to get an stacked connection scene and move a new connection to it?

#

Move a connection to an existing stacked scene?

kindred karma
#

Store the loaded scene reference or handle and use that to create scene lookup datas. Or there's exposed collections in SceneManager, eg SceneConnections to get which conns are in scene. Or conReference.Scenes

prisma ridge
delicate pierBOT
#

FirstGearGames received thanks.

prisma ridge
#

my code in case anyone's looking for it.

 //check if this scene has an entry against requested sceneId
        var loadedScene = LoadedConnectionScenes.GetValueOrDefault(request.SceneId);

        //if there's an entry, see if this scene is currently loaded
        var isValidScene = LoadedConnectionScenes.ContainsKey(request.SceneId) && loadedScene.isLoaded;

        //if there's entry and scene has previously been unloaded, remove the entry
        if (!isValidScene && LoadedConnectionScenes.ContainsKey(request.SceneId))
        {
            LoadedConnectionScenes.Remove(request.SceneId);
            Debug.LogError($"Invalid sceneId:{request.SceneId} is removed from LoadedScenes.");
        }

        //Make scene data and include scene if already loaded
        SceneLoadData sld = isValidScene ? new SceneLoadData(loadedScene) : new SceneLoadData(request.RequestedScene);
        sld.ReplaceScenes = ReplaceOption.All;
        sld.Options = loadOptions;

        sld.PreferredActiveScene = isValidScene ? new SceneLookupData(loadedScene) : new SceneLookupData(request.RequestedScene);
        sld.MovedNetworkObjects = movedObjects.ToArray();

        //Load for connection only.
        if (request.LoadAs == LoadAs.ConnectionScene)
        {
            UnitySceneManager.sceneLoaded += OnSceneLoaded;
            void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
            {
                UnitySceneManager.sceneLoaded -= OnSceneLoaded;
                if (scene.name == request.RequestedScene)
                {
                    if (LoadedConnectionScenes.ContainsKey(request.SceneId))
                        return;

                    LoadedConnectionScenes.Add(request.SceneId, scene);
                }
            }

            InstanceFinder.SceneManager.LoadConnectionScenes(conns.ToArray(), sld);
        }        //Load for all clients.
        else
        {
            InstanceFinder.SceneManager.LoadGlobalScenes(sld);
        }
#

the dictionary to keep track of loaded scenes

    private Dictionary<string, Scene> LoadedConnectionScenes = new Dictionary<string, Scene>();
kindred karma
#

Loaded scenes are already tracked by FN though

#

SceneManager.SceneConnections

prisma ridge