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.

How to sync a gameobject with common values

berke96
2022-03-27 22:25:23

So i have a card game where at the start any client(or master) do the shuffling and store the order of the cards in an game object's field, and another object stores a field that which client has which cards, in arrays. I added photonview to each of these scene objects, which are basic scripts. I raised an event after one of the clients finish the shuffling and distributing. My problem is after that it is not synched, the data about the ownership of the cards are only in the master.

Code's simplified version is like this. Can you tell me what i am missing?

And event controller:

Comments

Tobias
2022-03-28 14:57:51

First things first: You use RaiseEvent. Does the callback OnEvent get called, as you planned?

So far, you are sending event 1 with no content. So, how do you think the others know which cards they got?

Have a look at the Synchronization and State doc.

berke96
2022-03-28 15:32:50

Hi Tobias.

Yes I get the callback, but the CardsInHand object that I use is not up to date to the other clients.

The cards are stored in an empty object,

It's a scene object with PhotonView attached to it.

So my modifications on this cardsInHand on master actor won't be synced with others? Should i send all the data with my RaiseEvent? I thought marking them as photonview is making them sync with all clients 🤔

Tobias
2022-03-29 15:00:28

To avoid misconceptions like this, I'd recommend the PUN Basics Tutorial. It shows you what you can do with a PhotonView and how it syncs values. I won't be able to explain the basics one by one here.

A few notes:

PUN does not have "Sync Vars", where you modify values locally and they are automatically synced. Objects with a PhotonView can implement OnPhotonSerialiezView to do that.

Card is not a serializable datatype for PUN. If you try to send it, there should be errors in the log telling you about this failing.

Back to top