Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: kropcke on December 04, 2018, 11:37:02 AM

Title: Networking global variables via collisions VS. mouseclicks
Post by: kropcke on December 04, 2018, 11: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)

(https://www.asc.ohio-state.edu/swearingen.16/woods_server_host_001.png)

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)

(https://www.asc.ohio-state.edu/swearingen.16/woods_server_host_002.png)

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)

(https://www.asc.ohio-state.edu/swearingen.16/woods_server_host_003.png)

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).


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
Title: Re: Networking global variables via collisions VS. mouseclicks
Post by: jeanfabre on December 05, 2018, 01:45:38 AM
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
Title: Re: Networking global variables via collisions VS. mouseclicks
Post by: kropcke on December 05, 2018, 12:17:02 PM
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
Title: Re: Networking global variables via collisions VS. mouseclicks
Post by: jeanfabre on December 06, 2018, 01:11:45 AM
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
Title: Re: Networking global variables via collisions VS. mouseclicks
Post by: kropcke on December 08, 2018, 05: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
Title: Re: Networking global variables via collisions VS. mouseclicks
Post by: jeanfabre on December 12, 2018, 03: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