playMaker

Author Topic: Photon PUN2 - How to sync FSM variables?[SOLVED]  (Read 3671 times)

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Photon PUN2 - How to sync FSM variables?[SOLVED]
« on: January 08, 2020, 05:57:08 PM »
Hi Playmakers,

Using PUN 2 and Playmaker, I've got a Scene Object being instantiated. I need the variables in an FSM to be updated over the network, but it doesn't seem to be working.

When Player1 is spawned, he occupies a StartPoint1 and sets its BOOL 'Occupied _BOOL' to TRUE.

When Player2 is spawned, it checks to see if StartPoint1 is occupied, and if TRUE, he will spawn at StartPoint2.

It does not seem that Player2 is seeing the FSM variables update.

I thought that putting the FSM in the Observed Components would accomplish this, but as of now it's not working as intended.

I've attached an image of how I've got the StartPoint set up. I appreciate any help!
« Last Edit: February 07, 2020, 02:39:51 AM by jeanfabre »

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Photon PUN2 - How to sync FSM variables?
« Reply #1 on: January 09, 2020, 12:27:26 PM »
I changed the title to be more clear.

Basically, I need to know how to have an instantiated Scene Object's FSM variables to update to each player.

In my example, if player1 sets the FSM bool value to TRUE, Player2 will not see it changed to True.

How do I make PhotonView sync FSM variables across the network?

Thanks!

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Photon PUN2 - How to sync FSM variables?
« Reply #2 on: January 09, 2020, 03:27:43 PM »
I think I figured it out, but please let me know if there's a better way!!

1. The variables must have 'Network Sync' checked

2. Photon View must have the FSM as an observed component

3. A game object uses 'Photon View RPC Broadcast Fsm Event', with 'Master Client' as the RPC Target and 'Broadcast All' as the Event Target.

4. I used a Global Event 'VarUpdate' that will be used on many different objects. In order to make sure only the relevant objects react as intended, I added String Data to the RPC Broadcast Event (in this case 'StartPoint')

5. When the master client gets the event, the StartPoint receives the VarUpdate event, then gets Event String Data and tests it. If the String is 'StartPoint', then it continues to the next action and updates its variables.


ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Photon PUN2 - How to sync FSM variables?
« Reply #3 on: January 09, 2020, 03:29:41 PM »
However, I have not been able to get this to work on a child of an instantiated Scene Object. I can only get this to work if the PhotonView and FSM are on the top-level game object (not on children).

Can anyone advise me on how to get it to work on children of an instantiated scene object?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon PUN2 - How to sync FSM variables?
« Reply #4 on: January 13, 2020, 03:52:16 AM »
Hi,

You can only sync fsm who are observed by a photonView, so if you have a child, add a new entry to the parent photonView and target the child fsm, that should do it.

 however, it is recommand to have a dedicated fsm for synched variables and all other fsm will simply read and write to it, it will be easier to debug and more organised this way in the long term.

Bye,

 Jean

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Photon PUN2 - How to sync FSM variables?
« Reply #5 on: January 14, 2020, 05:42:21 PM »
Thanks, jean - that makes sense!

Here's a question:

I have a Scene Object with variables that are successfully syncing over the network. The problem is that when a new player joins, he sees the variables in their start state, even if they've changed. So if player1 changes a variable before Player2 joins, Player2 will not see the same value as Player1.

For example:

StartPoint1 is an instantiated scene object (instantiated by the master client). Starting values are:
Occupied=False
CharacterSelected=False

Player1 joins and StartPoint1 is set to Occupied=True

Player2 joins and sees StartPoint1 as Occupied=False, so Player1 is placed on StartPoint1 instead of StartPoint2

However, when Player1 chooses his character, StartPoint1 is changed to CharacterSelected=True
And Player2 sees the boolean change as expected

In other words, Player2 only seems to be getting variables synced if they are changed while he is in the room. He doesn't see any changes that took place before he arrived in the room.

Hope that makes sense - I appreciate any help!

*EDIT: I figured it out.

I have a Start state that sets all the variables to Occupied=False. I incorrectly assumed that this would only happen on the master client. It turns out that Player2 was resetting it's variables on join.

I fixed it by checking if it's on the master client. If true, set Start Variables. If false, do nothing. (Image attached)


« Last Edit: January 15, 2020, 10:29:53 AM by ToxicFrog »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon PUN2 - How to sync FSM variables?[SOLVED]
« Reply #6 on: February 07, 2020, 02:40:06 AM »
Hi,

 cool, thanks for letting us know.

Bye,

 Jean