Loading a scene with Unity's Addressable System

The traditional PhotonNetwork.LoadLevel() method doesn't work in loading scenes using addressables, since it can only load scenes that are in the build settings (with SceneManager.LoadSceneAsync()). I was wondering if anybody knows how to Photon load a scene referenced in the addressable groups

Comments

  • You have two options:

    Have a look at the PUN code that loads the scene and update it to work with addressables. It should be possible to replace the Unity API that's used with the addressable equivalent.

    Manually implement the loading, analog to what PUN does internally. Set a property, that contains the (addressable) scene name. When this changes, pause the message queue (IsMessageQueueRunning), load and re-enable the message queue when loading is done.

    Sorry, I can't provide actual code for this.

  • Okay, I've decided to just mix the two. I've set the location scene to load with addressables and the lobby and gameplay scene to load normally. However I also have a persistent managers scene, so I need to load additively. Photon load level methods by default don't do that, and when I change to load additively, the lobby scene is loaded multiple times (from OnJoinedRoom() and LoadLevelIfSynced()). So I turned off automatically sync scene, but now the OnJoinedRoom function won't work. Is there a way to solve this?

  • There is always some way to solve these things. Not knowing your project or any more context, I can't speculate what's up, however.

    Please let us know what this means:

    OnJoinedRoom function won't work

  • Oh sorry, what I mean is it doesn't get called. And that depends on whether automatically sync scene is on or off.

  • It's a feature I'd expect to see supported in the future, is it on the roadmap, and if yes any estimate?

  • We won't add support for Addressables to PUN, sorry.

    Addressables are fully supported by Fusion, which we'd recommend for newer projects.

  • Does PUN support addressables system?

    1. Hello, I am using addressables with pun in my project. I want to load a scene from my asset bundle which is not included in build settings. I tried changing the photonnetwork.load level method. When a player tries to join the room he gets this error: Scene Roomcreation couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded. To add a scene to the build settings use the menu File->Build Settings...

    2. Here is my code
    3. public static void LoadSceneAddressable(string levelName)
    4. {
    5. if (PhotonHandler.AppQuits)
    6. {
    7. return;
    8. }

    9. if (PhotonNetwork.AutomaticallySyncScene)
    10. {
    11. SetLevelInPropsIfSynced(levelName);
    12. }

    13. PhotonNetwork.IsMessageQueueRunning = false;

    14. loadingLevelAndPausedNetwork = true;
    15. Addressables.LoadSceneAsync(levelName, LoadSceneMode.Single);
    16. }


  • anyone found a solution? tq

  • RolandStudios
    edited June 2022


    I can't seem to add the necessary libraries ie

    using UnityEngine.AddressableAssets;

    using UnityEngine.ResourceManagement.AsyncOperations;

    using UnityEngine.ResourceManagement.ResourceProviders;

    to the PhotonNetwork.cs


    Tried modifying my own addressible scene load with toggling the  (IsMessageQueueRunning)

    but getting duplicate players on my end.


    Please add some level of support for this, or some hacky workaround... anything ... would mean so much :(

  • Addressables support will not be added to PUN 2 anymore, as it is now in LTS / maintenance mode. Sorry.

    You might want to look into Fusion for a much more capable solution (including Adressables support).

  • This is crazy. We have to use addressables due to large apk sizes we cant submit our game to Google play because the apk is too large to keep the scenes in. Google now forces you to use Android App bundles which no longer support traditional apk uploading and expansion files for asset bundles. You now have to use addressables to bundle your assets seperately as far as I can see this is a crucial feature?

  • I wasn't aware of that. While PUN 2 has no direct support of Addressables, it is not impossible to use them.

    Part of the problem is: PUN will have to immediately instantiate networked objects, or the "target" may be missing for incoming updates (and then there is no way to handle incoming messages and they get lost or entirely out of order).

    PUN 2 has the IPunPrefabPool, which you can use to create your own, Addressables-handling pool for instantiation. The condition is that you have to load Addressables before they are needed for instantiation. Aside from that, this will work very much "as usual" once the prefabs are known / loaded.

    There are a few discussions about using the pool here and the reference docs explain how to use the lean API.

    For loading Addressable scenes, you could manually pause the message queue as described in the docs or modify the PhotonNetwork.LoadLevel() code to fit your requirements.

  • Hello

    I would like to use addressable scenes with Fusion but I can't find how to proceed. I checked sample project about scene loading and doc but I don't understand how to implement it.

  • You need to add the assembly reference for UnityEngine.Addressables and UnityEngine.ResourceManager to the assembly definition asset in the PhotonNetworking.cs folder. Only then it can be scoped in PhotonNetwork.cs