Photon Cloud Networking: OnPhotonSerializeView Not Firing

Hello everyone, let me start by saying that I’m having the exact same problem as this fellow:

I recognize “tobiass” is one of the Photon engineers and I would much rather post in their forums, but the registration email isn’t getting sent to me so hopefully he’ll find his way here, eh?

Just like that guy in the forum I linked, my OnPhotonSerializeView of the Observed “PlayerNetwork.cs” script is not getting fired. I don’t really understand Tobiass’ answer: “If you actually implemented “OnPhotonSerializeNetwork”, it’s no wonder it’s not called.” What does he mean by ‘implemented’? I know I’m missing something super-simple, but combing the tutorials hasn’t fixed anything yet.

I’m converting my existing single-player game based on the Marco Polo tutorial from Photon as well as by examining the Viking Demo they’ve put together. In the Viking Demo, the Observed script on PhotonView has an OnPhotonSerializeView function, and it’s getting called.

  • “playerMain” is the prefab; it’s in the Resources folder and it instantiates fine using PhotonNetwork.Instantiate();
  • The prefab has a “PhotonView” script, and that script obseves “PlayerNetwork.cs” which contains the OnPhotonSerializeView that isn’t firing.
  • OnPhotonSerializeView is spelled correctly in the code.

Thank you guys so much for any help you could offer.

I think i had the same problem. I solved it by rereading the Marco Polo tutorial. It says

We need another script. Create a “NetworkCharacter” C# script in the Marco Polo folder. Add it to the “monsterprefab” and make it the observed component of the PhotonView(drag & drop).

This means that we first have to have a PhotonView on our prefab, then we need to add this NetworkCharacter script to our prefab and then we need to drag this NetworkCharacter script to the Observe property of our PhotonView.

Now the Observe property will look like this

Observe: (NetworkCharacter) CarPrefab

Instead of this

Observe: (UnityEngine.Transform) CarPrefab

Now the OnPhotonSerializeView will fire

I hope this helps

“implementing it” means that you must have a C# script with the following code in it:

void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
//Your code here..

Furthermore, make sure that this script is set as “observed” for that PhotonView.
It looks like you have already done so.

Also note that it is only called when at least 1 other player is connected, maybe this is what you’re missing?

I don’t mean to gravedig, but as this is the first page that google shows I’ll post:

you drag the actual component drop-down in the inspector onto the photonview, i just spent ages finding out why dragging the script wouldnt work.

first put the prefab into the scene.

then make the script get observed in the inspector.

then apply the changes to the prefab and destroy the object in the scene.

After those steps the script should work fine.

I have the same problem, i cant get observed my prefab, it has all components needed, i checked the code many times and dont work.

Can anyone post a download link of the tutorial please?

This was the top hit on google for my issue, and I solved it after a short while of hair pulling. Just wanted to post my solution in case it helps anyone else, even though it was quite a “well duh” moment.

Make sure the GameObject, on both the writing side and the reading side, is active in the hierarchy. Else OnPhotonSerializeView won’t get called.

I just spend hours to figure this out too and unfortunately all answers here are completely UNSATISFIED.

First of you all your class has to be derived from Photo.MonoBehavior

public class PlayerMovement : Photon.MonoBehaviour {

Then you have to PUT THIS CLASS on the Observed Componts in your PhotonView.
The tricky part is if you have multiple Stuff on the same gameobject and you put it into the Oberserver it will automatically take the TRANSFORM and not check all scripts and picks up the Photon.MonoBehavior one

CORRECT (look at the Observed Components only)

INCORRECT (look at the Observed Components only)

And this is only fired when there are at least two players in the game. Host (master) + 1 player

My problem was because i didn’t drag my custom component into the Photon View.