Non Resource located network prefabs.

Hi,

I have a request for Photon PUN so you guys can take into consideration, let me explain:

I have a Multiplayer Kit in the Asset Store which uses Photon PUN 2, I have received some similar questions related to the game build size, which is caused by all the content that is included in the Resources folder and since Photon by default requires that any prefab that is instantiated by PhotonNetwork.Instantiate(...) need to be located in a Resources folder, devs can't build these assets in an Asset Bundle or Addressable, so it has to be build-in the main game package causing it to be heavy in size, that is especially a problem for mobile games.

For my own games, I have fixed this by modifying a few lines in Photon PUN code, but for my kit in the Asset Store, since I'm now allowed to include your package, users have to download it from your publisher page so I can't fix it.

So I request the addition of this feature: Add Non-Resourced located prefabs in the PrefabPool of PhotonNetwork in order to be able to instantiate with PhotonNetwork.Instantiate.

That could be optionally and not a replacement for the actual system, of course, let developers that need it used it.

I managed to do this by adding this function:
void RegisterPrefab(string prefabID, GameObject prefab);
in IPunPrefabPool interface, and implemented in the class: public class DefaultPool : IPunPrefabPool (PunClasses.cs) like this:
/// <summary>
        /// Register prefabs to be network instantiated that are not located in a Resources folder.
        /// </summary>
        /// <param name="prefabID">String identifier for the networked object.</param>
        /// <param name="prefab">The prefab to be instantiated.</param>
        public void RegisterPrefab(string prefabID, GameObject prefab)
        {
            if (!this.ResourceCache.ContainsKey(prefabID))
            {
                ResourceCache.Add(prefabID, prefab);
            }
            else
            {
                Debug.LogError($"A prefab was already registered with the key '{prefabID}' make sure you use a unique Key for each prefab or not registered multiple times.");
            }
        }

So I can use like this:
PhotonNetwork.PrefabPool.RegisterPrefab("MyPrefabID", MyPrefab);

Hopefully, you guys take this in consideration and support it by default,
Regards.

Comments