Custom Spawning
Hi! I've been using Photon Unity (PUN) for quite some time.
In most projects I've opted to handle the spawning of objects myself so I can use my own pooling. In PUN this was relatively straight forward, I'd just need to send over the ViewID and set it manually along with the correct owner.
Is this also manageable in Fusion or is it more complex?
Thanks,
Myles
Comments
-
I would also like to know how this could be done. @myleslambert , have you figured it out?
0 -
Hi, it's possible to do your custom pooling passing an instance of the
INetworkObjectPool
to yourStartGameArgs.ObjectPool
when starting the runner.The interface ask for 2 methods implementations, referring to
AdquireInstance()
andReleaseInstance().
If no
INetworkPool
implementation is specified, theNetworkRunner
will use this internal default implementation. The default implementation does not pool objects, and instead will just creates aNetworkObject
from scratch onSpawn()
and destroys the instance onDespawn()
class NetworkObjectPoolDefault : INetworkObjectPool { public NetworkObject AcquireInstance(NetworkRunner runner, NetworkPrefabInfo info) { if (runner.Config.PrefabTable.TryGetPrefab(info.Prefab, out var prefab)) { return Object.Instantiate(prefab); } return null; } public void ReleaseInstance(NetworkRunner runner, NetworkObject instance, bool isSceneObject) { Object.Destroy(instance.gameObject); } }
You can use it to create your own pooling system.
A page about it it's already being deployed and should be live soon, but i believe that the
Tanknarok
sample has a showcase for that.Hope that helps.
-----
Isaac Augusto
Photon Fusion Team
1 -
Thank you @Isaac_Augusto , I'll give it a go.
0 -
Thanks Isaac!
Is it possible to feed in a custom prefab id into the system? For example I already have a unique id for all spawnable prefabs for my save system and would like to reuse the same id for simplicity.
Also it doesn't look like this will work for any sort of async prefab loading. Is that something that could be supported? Where a few frames might pass when acquiring prefab instances?
Thanks,
Myles
0