- Home /
Photon Cloud Networking: OnPhotonSerializeView Not Firing
Hello everyone, let me start by saying that I'm having the exact same problem as this fellow:
http://forum.unity3d.com/threads/103953-Problem-using-PhotonViews-from-the-Photon-Plugin
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.
Answer by luckruns0ut · Sep 23, 2013 at 08:53 PM
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.
This is correct. You need to drag the actual component from the inspector onto that variable on the same object. When I asked this, I still had no idea I could do that! Hahaha.
Answer by FuZZbaLL_b · Feb 25, 2013 at 08:02 AM
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
I've not got the rep to upvote this yet; It solved the problem perfectly for me. $$anonymous$$uch clearer explanation than all the others too!
Just to add, you have to drag the component from the header (checkbox area) not from the script reference itself within the component.
Answer by MikeHergaarden · Sep 05, 2012 at 09:34 AM
"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?
Thanks for your last point, I didn't realize it would be only called when at least one other player is connecter
Answer by nikita68 · Feb 08, 2013 at 02:39 PM
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.
as unlikely as this solution sounds, it is the only one that worked for me.
Answer by Yuu-Interactive · Jan 14, 2013 at 05:25 AM
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.