Photon Instantiating a local GameObject that doesn't exist in any Unity folder

Options
I have a model that I load from a remote webserver at runtime and it created a local gameobject in my unity scene. Is it possible to photon instantiate this for sharing? If so, what method can be used? An example would be much appreciated

Answers

  • Tobias
    Options
    We don't have an example for this but you should be able to make use of a custom instantiation pool.

    Have a look at the PhotonNetwork.PrefabPool. You implement a IPunPrefabPool according to the reference docs and should be able to pass any object you like into PUN.

    A hard condition for this is: The object needs to be available in the very moment the PhotonNetwork.Instantiate is being called (locally and or remote via message).

    Alternatively, you can experiment with instantiating a more or less empty networked object and have that load the asset asynchronously. Let's say you instantiate a character with a default skin but it begins to load another asset as skin and applies it when done.
    For that, I would use the last parameter of PhotonNetwork.Instantiate(..., instantiationData), which can (e.g.) pass some configuration to the instantiated object (which tells you the asset to load).
  • wilko
    Options
    Thanks Tobias. So in my case, I start my project and it takes about 8 secs for the model to appear in the hierarchy as a gameobject. Are you saying that I can reference that gameobject using ipunprefabpool or does it require an actual prefab to reference?
  • Tobias
    Options
    The IPrefabPool has to provide the actual, correct object. Immediately.
    So you could load the asset earlier, then have it ready when instantiate happens, or you pass a dummy, then replace it as soon as the actual asset loaded.