playMaker

Author Topic: Syncing gameObject variable over network  (Read 12367 times)

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Syncing gameObject variable over network
« on: May 29, 2014, 12:45:01 PM »

Hey Guys,

I know that we are unable to sync GameObject variables over the network. So I was wondering  for example if a player updates the target for a turret and that is saved as 'Target' variable. How does this change get transmitted to other players so their games know that the target has changed and what it is targeting?

Cheers
Terry

cmy

  • Playmaker Newbie
  • *
  • Posts: 40
Re: Syncing gameObject variable over network
« Reply #1 on: May 29, 2014, 03:14:49 PM »
You'll need to use an RPC call so each client locally sets the desired target.

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #2 on: May 30, 2014, 04:28:01 AM »
Hey cmy,

Thanks for the reply. Yeah I assumed thats what I would have to do. I suppose then its a case of how do the clients know which target to set? I have to pass some kind of information across the network that identifies which target a client has chosen.

Have you done much work with this? I noticed one of your other posts on networking. It doesnt seem that many people using playmaker do networked games, or at least dont seem to have any issues with them :)

THanks again

Terry

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Syncing gameObject variable over network
« Reply #3 on: May 30, 2014, 07:54:46 AM »
Hi,

 the issue here is that you can't pass a reference to a gameobject over the network, it's doesn't work like that.

 a GameObject variable is a "Pointer" to an internal memory within the Unity engine that is unique for the game. It should not be assumed that because you have a gameobject of the same name, or even with the same components with the exact same settings, you will be able to keep the pointer across the network.

 The likely solutions are:

-- Unique gameobjects naming convention, so that you can simply call an rpc with a string of the name of the gameobject, and on the reception of this rpc call, you do a "find" for this gameobject's name on that instance.

-- Make the target with a networkview so that it is indeed recognyzed across the network. And so you can send an rpc call to that gameobject across the network like "YOU ARE NOW THE TARGET" or something.

 Does that make sense?

bye,

 Jean

cmy

  • Playmaker Newbie
  • *
  • Posts: 40
Re: Syncing gameObject variable over network
« Reply #4 on: May 30, 2014, 12:16:09 PM »
tezer86,

Typically what I do for this kind of stuff is on your target object make 2 states each with a global event attached to it. As an example call the events "Set Target" and the other "Set Target RPC"

Set Target should locally set the turret target for your own client but the trick is to include an RPC call (Set Target RPC) in the event that targets "self" and sends it to "others".

The only difference between the two states is that the local one includes an RPC call, the RPC state does not (if it did you would have an endless loop of RPC calls being sent out), otherwise they should include exactly the same actions.

So "Set Target" would be triggered locally with "Send Event", it sets the target locally and also fires off the RPC event "Set Target RPC" to "self" for "other" clients.

This is basically what I mean, below I'm using one state to trigger an RPC call. This way I can tell a game object to locally create some particles instead of needlessly instantiating them across the network. Then the particles themselves monitor when they are no longer needed and self destruct.

In a 4 player game I'm easily pin-pointing who is poisoned and what should be done about it.



« Last Edit: May 30, 2014, 12:30:21 PM by cmy »

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #5 on: June 10, 2014, 06:05:34 AM »
Hey Guys,

Thanks so much for the information, I just got back from my holiday and I've been waiting to get back on and try some of this stuff.

@cmy - Even more thanks for taking the time to send over an example screenshot and explain it in depth. I will report back hopefully with a success story.

Will let you know how it goes!

Cheers
Terry

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #6 on: June 10, 2014, 02:56:35 PM »
Hey Guys,

Right I have had a crack at this today, the issue I seem to be having is that the RPC event doesn't seem to send over the network at all.

- Im using just unity local network function, not the Photon stuff.
- Camera has the move scripts on for a cube that is instantiated.
- Cube and camera both have network view.


So I can instantiate a cube over the network, it has a network view on. Which ever person instantiates the cube when they move all others see it. Without even sending an RPC. When the others move the cube I try and send and event via RPC to a global event that should then trigger a move in the local game of 'Others'.

I have tried only instantiating the cube on the server and sending all moves from clients to the server so that the server will does all the moves. This doesnt work as the global events never trigger. I then tried letting anyone instantiate the cube and then anyone that moves the cube send RPC global events to 'others'. This doesn't seem to work either.

The issue I seem to be getting is that I can't send a successful RPC to trigger a global event. :(

« Last Edit: June 10, 2014, 03:22:32 PM by tezer86 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Syncing gameObject variable over network
« Reply #7 on: June 11, 2014, 01:23:13 AM »
Hi,

Can you tell us about your server configuration.

Does your server log your client as connected in the first place?

bye,

 Jean

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #8 on: June 11, 2014, 02:00:40 PM »
Hey Jean,
My server is listening on the 25001 port, I then connect to the IP 127.0.0.1 which is my machine. When I check for connection I get one successful connection.

I then boot up an exe and run the other through unity. Either can host the server but whoever instantiates the object is the only person that can affect it.

Does that all sound correct?

Cheers
Terry

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #9 on: June 11, 2014, 02:25:25 PM »
Update - It seems when I try and send a remote event to another fsm to trigger a Global event, the global event does not come up in the drop down. So Send remote event doesn't get all global events?

If so, what are you sending a remote event to?

I thought it was a case of: Send remote event to another fsm on another client that has a global event waiting to be triggered. That event is then triggered. Is this not how it works?

Thanks again for all of this.

Terry

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #10 on: June 16, 2014, 06:31:40 AM »

Is there actually a way of triggering a global event over a network? I using the event RPC? Or do I have to use Photon? I only want the game to be LAN.

The only issue I seem to have is triggering in event in another client.

CHeers
Terry

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Syncing gameObject variable over network
« Reply #11 on: June 16, 2014, 03:18:26 PM »
Hi,

Indeed, I confirm that there is a problem. I'll investigate further to see where things goes wrong.

Bye,

 Jean

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Syncing gameObject variable over network
« Reply #12 on: June 17, 2014, 01:55:38 PM »
oh great, I thought I was going crazy.

Looking forward to the fix!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Syncing gameObject variable over network
« Reply #13 on: June 18, 2014, 04:16:05 PM »
Hi,

Can you check this thread and see if the solution provided works for you?

http://hutonggames.com/playmakerforum/index.php?topic=7652.0

Bye,

 Jean