Instantiate without prefab name
Options
Hi,
I'm trying to instantiate a Gameobject, that is part of a Gameobject array. So I have an Array with different GameObjects (different meshes etc). Using traditional Instantiate I can instantiate my player/prefab by calling
GameObject name = Instantiate(arrayname[array-integer], transform.position, quaternion.identity) as Gameobject;
now I tried to modify this to suit PhotonNetwork Instantiate:
GameObject name = PhotonNetwork.Instantiate(arrayname[array-integer], Vector3.zero, Quaternion.identity, 0);
however PhotonNetwork Instantiate expects a prefab name. While my prefab does have a name (the array that is) that wouldn't tell PhotonNetwork which one of the gameObjects I want to have instantiated. I hope you see my problem and I'm hoping somebody here has a solution other than splitting my array into individual prefabs and calling them by name - how difficult can it be to load a gameObject by calling the Object directly instead of looking up its name?
I'm trying to instantiate a Gameobject, that is part of a Gameobject array. So I have an Array with different GameObjects (different meshes etc). Using traditional Instantiate I can instantiate my player/prefab by calling
GameObject name = Instantiate(arrayname[array-integer], transform.position, quaternion.identity) as Gameobject;
now I tried to modify this to suit PhotonNetwork Instantiate:
GameObject name = PhotonNetwork.Instantiate(arrayname[array-integer], Vector3.zero, Quaternion.identity, 0);
however PhotonNetwork Instantiate expects a prefab name. While my prefab does have a name (the array that is) that wouldn't tell PhotonNetwork which one of the gameObjects I want to have instantiated. I hope you see my problem and I'm hoping somebody here has a solution other than splitting my array into individual prefabs and calling them by name - how difficult can it be to load a gameObject by calling the Object directly instead of looking up its name?
0
Comments
-
Our instantiate requires the name of a prefab. If you have prefabs in your array, you could simply call it: arrayname[array-integer].ToString() or .Name, I guess.
If the objects from the array are more or less blueprints, then you could instantiate them more or less manually, as described in the pdf thats in the download.0 -
don't forget that even if you have it in the array and provide the name: Its instantiated from Resources folder as you can not send prefabs over the network. The name will be sent and looked up on all clients to replicate the instantiation there1
-
Our instantiate requires the name of a prefab. If you have prefabs in your array, you could simply call it: arrayname[array-integer].ToString() or .Name, I guess.
If the objects from the array are more or less blueprints, then you could instantiate them more or less manually, as described in the pdf thats in the download.
what if i dont have prefab but an gameobject on the current scene then how do i instantiate that gameobject in the multiplayerlevel loaded by photonnetwork0