- Home /
Photon instantiates all Network instantiated Objects again when other Players connect?
I am having some weird behaviour that past instantiated gameObjects (already destroyed) from other clients get also instantiated on the others when re- and connecting. This issue appears as long as the client that has called to "PhotonInstantiate" the prefabs is still on the server.
For example I have thrown a grenade in the editor client and it has exploded.
Then I run a second client (the built). When it connects to the server, this grenade gets also spawned only on this client again. Unfortunalty, because of the grenades last position before explosion on the editor was at the global spawnpoint, this player gets instant killed after joining the server.
The grenade is called by this code:
GameObject projectileClone = PhotonNetwork.Instantiate("Projectiles/" + projectile.name, bulletEmpty.position, transform.rotation, 0);
The prefab has an photonview component with its transform as observed component, set fixed, unreliable on change and position and rotation.
Answer by N1warhead · Mar 05, 2017 at 12:05 PM
Don't ever use PhotonNetwork.Instantiate for things such as projectiles, this is probably your problem. You need to use an RPC.
Here's an example
public PhotonView pv;
public GameObject gren; // our grenade.
void Update(){
if (Input.GetKeyDown (KeyCode.G)) {
pv.RPC ("ThrowGrenade", PhotonTargets.All);
}
}
public void ThrowGrenade(){
GameObject grenade = Instantiate (gren, transform.position, Quaternion.identity) as GameObject;
}
This way it creates the Grenades locally only to connected players.
Your answer
Follow this Question
Related Questions
Photon synchronization on different devices failes 0 Answers
Object Not Instantiating After Being Destroyed 0 Answers
Photon client objects behave strangely when colliding 0 Answers
Instantiating Multiple Game Objects to the Position of a Current GameObject 2 Answers
How can I get PhotonPlayer GameObject 0 Answers