Cant add prefab to game.

Hi all,

I'm trying to get my game to create a prefab across to all players in the game. However, I keep getting a compile error :(.

if(placeBox == true){
Object[] dataHolder = new Object[0];
PhotonNetwork.InstantiateSceneObject(Box, new Vector3(50,50,50), new Quaternion(0,0,0,0), 0, dataHolder);
}

This is the code I'm using to spawn the object. and heres the error I'm getting.

Assets/Scripts/Game/SpawnBox.cs(19,31): error CS1502: The best overloaded method match for `PhotonNetwork.InstantiateSceneObject(string, UnityEngine.Vector3, UnityEngine.Quaternion, int, object[])' has some invalid arguments


thanks in advance

Comments

  • It's a bit counter-intuitive maybe but just like the message says: No variant of PhotonNetwork.Instantiate() accepts a gameobject as blueprint to instantiate.
    The reason for this is that once the object is instantiated, the remote clients have to also instantiate this exact prefab/object. If this is any reference you have under control, PUN can't make sure that remote players find this GO, too.
    So, the rule is you can only instantiate prefabs that are in the Resources folder and only by their name (filename, as shown in project browser in Editor).