Reputation: 69
SUMMARY: I need to use PhotonNetwork.InstantiateSceneObject(string prefab_name) to instantiate an object that is in an AssetBundle.
At run-time I download a Unity asset bundle from the internet that contains a bunch of prefabs. Then i want to use PhotonNetwork.InstantiateSceneObject to Instantiate some of the prefabs, but this function only accepts a prefab name string, but all the prefabs are inside the asset bundle and only accessible if you first load the object as a prefab, and then instantiate it. You cant Instantiate it as a string name directly like you would if it was in the Resource folder.
AssetBundle ab=AssetBundle.LoadFromFile("c:\assets\bundlename.android");
var prefab=ab.LoadAsset("networked_monster.prefab");
PhotonNetwork.InstantiateSceneObject("networked_monster.prefab"); <<------ this wont work, cant access asset bundle from Photon
Is there a way to unpack all prefabs and other objects in the asset bundle so that it appears as if all of them are located in the resource folder??? Then i will be able to access them like this
PhotonNetwork.InstantiateSceneObject("networked_monster.prefab");
AudioClip audio=Resources.Load("BangZoom") as AudioClip;
Here BangZoom is a wav file that was inside the asset bundle and i need it to appear as if its in the resource folder.
Also "networked_monster.prefab" was in the asset bundle, i need it to appear as if its in the resource folder so i can instantiate it by name.
Also how to I unload and free all these assets when im done with them?
Upvotes: 0
Views: 1571
Reputation:
I just answered on our forum for the same question: https://forum.photonengine.com/discussion/14956/photonnetwork-instantiatesceneobject
basically, you simply implement your own IPrefabPool Interface and then you are free to instantiate network object the way you want.
Please check the default implementation (DefaultPool class in punclasses.cs) for an example.
For unloading, I am not sure, it would be best to ask on Unity forum or UA.
Upvotes: 0