Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Server+Client updating properly, but Client Only is not

Discussion in 'Multiplayer' started by Carcophan, May 16, 2022.

  1. Carcophan

    Carcophan

    Joined:
    May 10, 2021
    Posts:
    79
    Hello everyone.

    I'm new to using Mirror. I've tried following several guides, and have a scenario that I still can't figure out. I'm not even sure how to properly word my question / highlight my issue, sorry in advance.

    I am basically just sending a Random number, that I want both players to be able to view. The Server+Client window is correctly updating a shared screen text / UI element, but the Client only window is not updating that same shared text properly.

    The Server+Client player (Player303, in the top image here) has rolled a 4 and a 12. Both upper text elements update properly on both screens (bottom screen shows 'Player303 4 12, as expected) so both players can see the "Player303 4 & 12"
    upload_2022-5-16_12-33-49.png


    However, when player 2 (Player 116, who is in control of the bottom here) clicks their random button... it properly updates their OWN UI (to show the 5 and 1) but the SHARED text just above it, shows an invalid value of 6 and 6.
    upload_2022-5-16_12-35-44.png

    It is defaulting to the hard coded static float variables within the script itself, but only for the 'shared' text element. The non-shared, my-window-only text, does get updated as needed.
    public float ran1 = 6f;
    public float ran2 = 6f;

    Why is it properly updating its own UI element with the '5 and 1', on its own screen, but then sending the default 6 and 6 values to the shared text element above it? And only on the client, as it does not happen on the Server+Client window.


    In the Scene Script, triggered by a UI button:
    public void Ran_Button()
    {
    playerScript.ran1 = Random.Range(1, 20);
    playerScript.ran2 = Random.Range(1, 20);

    //update the UI with the new values
    Value1Text.text = "" + playerScript.ran1;
    Value2Text.text = "" + playerScript.ran2;

    playerScript.RanButtonUpdate();
    }

    In the player script:
    public float ran1 = 6f;
    public float ran2 = 6f;
    [Command] //[ClientRpc] using this seems to have no change
    public void RanButtonUpdate()
    {
    sceneScript.statusText = $"{playerName} {ran1} {ran2}";
    }

    Each UI is updated with the new random values, per the button click, but the shared text is not being updated properly - it just shows the default 6/6's from "public float ran1 = 6f;"

    Any thoughts?
    Thanks all
     
  2. Carcophan

    Carcophan

    Joined:
    May 10, 2021
    Posts:
    79
    Separately, but I still think related to my overall problem (which is a lack of a full understanding of networking), is this...

    upload_2022-5-18_17-46-4.png
    Player1 is on the left image, looking at player 2. Player 2 is on the right image, looking at player 1.

    I put a child object (the white cube) on my player prefabs head. Each player can see their own cube, on their own head, on their own screen.

    However, you do not see that same cube child object on the other player.

    Notice the left screen/cube... that is where the player spawned in. To player 1, player 2's cube hasn't moved... but on player 2's own screen, that same cube is properly on its head.

    Why is it 'correct' on their own screen, but when another player views it, it hasn't moved from spawn?
     
    Last edited: May 21, 2022
  3. Carcophan

    Carcophan

    Joined:
    May 10, 2021
    Posts:
    79
    Regarding the second post here, the cube on the head...

    Is part of the problem that the cube is a child of the player object?
    upload_2022-5-23_15-34-51.png

    Does this cause an issue because the character is part of the Network Manager script?
    upload_2022-5-23_15-35-50.png

    I'm trying to experiment now and figure out how to best cut it from being a child of the Monster-5 object and make it its own stand along object in the room - but why would this be required (if it even is)?

    Is there something about it being a child and using movePointObj.transform.position = new Vector3(movePointLoc.position.x, yVal, movePointLoc.position.z); that is the problem?