playMaker

Author Topic: Networking global variables via collisions VS. mouseclicks  (Read 536 times)

kropcke

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Networking global variables via collisions VS. mouseclicks
« on: December 04, 2018, 09:37:02 AM »
Hi All.

I have a question about networked global variables, and setting them ingame via collisions VS. mouseclicks.

For my network test, the LAN Host is running inside my Unity Game window, while  a build of that scene is connected to it using LAN Client. The orange ball on the left is controlled by the LAN Host (on the left), and the orange ball on the right is controlled via the LAN Client (on the right). (see below)



When I move either ball into the green rectangular trigger, the global variable var_tr_1a is set to '1'. The red box at the bottom turns green whenever var_tr_1a is set to '1'. The global variable var_tr_1a is responding to collisions via the 'Trigger Event' Action in an FSM within the orange ball. (see below)



I also have the green rectangular trigger set to respond to Mouse Pick Events, specifically Mouse Down and Mouse Up. This is also achieved through an FSM in the green trigger. In the screenshot below, I'm mouseclicking on the green rectangular trigger in the LAN Client to the right. The global variable var_tr_1a only gets set to '1' here. You can see the value of var_tr_1a is still '0' on the LAN Host to the left. (see below)



At this point, I feel like I'm heading a bit too far down the rabbit hole and am losing track of what changes I'm making really matter in helping to resolve this: updating global variables across the network using both collision (which is working) and mouseclicks (which is currently not working).

  • the orange ball, the green trigger, and the red/green square are all prefabs that I'm spawning
  • they all have a network identity (that has been set and reset to every combination of local and server authority I can think of)
  • my network manager is spawning the orange ball as the player prefab
  • the green trigger and red/green square are both registered spawnable prefabs
  • the eventMouseUp and eventMouseDown events on the green trigger are global events, and I Broadcast All using a Send Event action in its FSM
  • the orange ball prefab has a player script attached to it that is not associated with an FSM. It has some ClientCallback and Command calls that I'm not familiar with, but am wondering if this is affording the orange ball something that the other two prefabs are missing out on?

Please let me know if you have any ideas, or if there's something else I haven't yet considered that you think I should give a shot. I really appreciate any advice you might be able to share.

Sincerely,
kropcke

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14595
  • Official Playmaker Support
    • View Profile
Re: Networking global variables via collisions VS. mouseclicks
« Reply #1 on: December 04, 2018, 11:45:38 PM »
Hi,

 I would make sure that programmatically you can control the global variable properly and that it's value is propagated across all clients, then you bring complexity using mouseclicks or other tricks.

 in your case, is it not a case that both clients listen to the mouse click and so conflicts in what they should do with values?

I would debug mouse clicks visually for both clients to make sure it's not that.

Bye,

 Jean

kropcke

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: Networking global variables via collisions VS. mouseclicks
« Reply #2 on: December 05, 2018, 10:17:02 AM »
Hi Jean.

Thank you so much for your response.

The global variable is definitely propagating across the network when I update its value using colliders. However, what you point out is interesting with regards to both clients listening for the mouseclick, and that there might be conflicts there.

The object that responds to 'mouseclicks' is the same spawnable prefab that the colliders interact with. Its just that colliding with it will update the global variable across the network, but 'mouseclicking' it will not.

The movement script that handles the orange ball (which collides with the spawnable prefab) uses CLientCallback and Command to handle network behaviors. I guess this might be the difference?

Will keep looking.

Thanks again!
-Scott

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14595
  • Official Playmaker Support
    • View Profile
Re: Networking global variables via collisions VS. mouseclicks
« Reply #3 on: December 05, 2018, 11:11:45 PM »
Hi,

 yes, you'll need to match what you do with the colliders, there is no reasons that the network has an issue when one way works and the other not.

Bye,

 Jean

kropcke

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: Networking global variables via collisions VS. mouseclicks
« Reply #4 on: December 08, 2018, 03:26:50 PM »
Hi Jean.

Per your suggestion, I'm applying my player/collider script to the green rectangular trigger, and rewrote it to account for 'GetMouseButtonDown/Up'. It almost works...

When I click the trigger on the server, the red box turns green on both the client and the server. Hooray! This part is working  :) However, when I click the trigger on the client - nothing happens and both boxes stays red.

I would like the box to turn red on both the server and the client, regardless who clicks it.

Here's my code:

Code: [Select]
using UnityEngine;
using UnityEngine.Networking;
using HutongGames.PlayMaker;

public class MouseDownYes : NetworkBehaviour
{


    void Start()
    {
    }

    [ClientCallback]

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RpcMouseDownYes();
        }

        if (Input.GetMouseButtonUp(0))
        {
            RpcMouseDownNo();
        }
    }

    [ClientRpc]

    public void RpcMouseDownYes()
    {
        Debug.Log("Pressed primary button.");

        FsmInt globalVar = FsmVariables.GlobalVariables.FindFsmInt("var_tr_1a");
        globalVar.Value = 1;
    }

    [ClientRpc]

    public void RpcMouseDownNo()
    {
        Debug.Log("Pressed primary button.");

        FsmInt globalVar = FsmVariables.GlobalVariables.FindFsmInt("var_tr_1a");
        globalVar.Value = 0;
    }

}

I'm not sure if my Playmaker setup is screwy, or if the scripting to support it is. I feel like I'm really close, but I'm not sure how to tackle the problem. Any advice would be really appreciated. Thanks so much already for all your help.

Sincerely,
kropcke

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14595
  • Official Playmaker Support
    • View Profile
Re: Networking global variables via collisions VS. mouseclicks
« Reply #5 on: December 12, 2018, 01:39:36 AM »
Hi,

 it's because the client doesn't have the same rights as the server, only the server can send RPC, client must send messages to the server and the server will then check and send rpc based on your logic.

Bye,

 Jean