The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

SYNC INSTANCIATE ENEMY (ZOMBIE) with Photon PUN 2

elyes
2020-12-04 23:36:45

hi to the whole community i hope you are doing well!

I'm trying to create a multiplayer FPS game with Pun 2 photon at this moment I can instantiate the players as needed, shoot them, take damage etc ...

I want to add enemies (zombie) in the game.

Until then I managed to instantiate the zombies by attaching a script to game scene and using photonNetwork.InstantiateRoomObject (Combine.Path ...), I can observe them with all clients correctly.

the problem is that when I want to change the names of the zombies (to store them in a GameManager dictionary (ZombieName, Scriptzombie)), it changes only with the master client!

I tried instantiation with RPCs but still nothing, the other clients will receive zoombie.clone in the hierarchy, I have tried everything I have read all the forums but still nothing, that someone can help me it's been several days and night that I try to solve this problem.
Credibly.

Comments

elyes
2020-12-05 21:46:22

anyone can help please ?

ThomasKao_XRSpace
2020-12-07 05:41:03

for the information at the time of Instantiation you can use

and then you can read the data from photonView.InstantiationData in either Start() or

After the Instantiation stage, you might encounter sync problem because the ownership.
As you Instantiate those as Room/Scene object, you migt want to give ownership to specific player just after creation.

elyes
2020-12-08 04:14:20

thank you very much for answering me,

your trick works like magic, I can now sync a single zombie for all clients and shoot them, kill them etc ...
but the public void function OnPhotonInstantiate (PhotonMessageInfo info) does not work if I instantiate two zombies, I cannot rename each by itself, if I change name both zombies will have the same !!

to better understand me:
in gameManager I instantiate the two zombies as follows:

for (int i = 0; i <2; i ++)
{
nameZomby = i.ToString ();
zombieInstantiated [i] = PhotonNetwork.InstantiateRoomObject (Path.Combine ("PhotonPrefabs", "zombie"), new Vector3 (i, 0, i), Quaternion.identity); //. transform.name = i.ToString ();
}

PS: if I change the name by instantiating them, it will only concern the master client !!

and on the zombie script:
public void OnPhotonInstantiate (PhotonMessageInfo info)
{
object [] instantiationData = info.photonView.InstantiationData;

it also works only on the master client!

ThomasKao_XRSpace
2020-12-08 04:24:31

As I mentioned, put the zombie name inside Instatiate data

and then

elyes
2020-12-08 08:41:20

it works perfectly again thank you very much your constant help, you saved my little project i hope to make you a faver one day ThomasKao_XRSpace

Back to top