Network Transform

After Build & Run , I have noticed that When the player on Non-Editor Side( Build & Run Window) doesn’t move or we can say the number of transform doesn’t change.

I have tried changing the script ( by unchecking the other 2) Also tried selecting all 3 , but still the Transform for “Build & Run” never change, its like it is freezed or Locked in Inspector.

please help me,

Notice for Above condition : When the Host was from the EDITOR.,

When I tried Hosting in Build&Run Window ,
ON moving those Spawned Player Prefab I found that the Player-1 ( which belongs to the Hosting side on Build & Run Window) the movement not Sync coz in Editor Window it shows the movement goues on respective Axis, But on the Build & Run it is not moving.

Where on the Other hand I noticed on Moving Player2 (which belongs to the Editor Side) the Movement was Sync . the Player-2 movements was on the both Screens ( Build & Run as well as in Editor Window)

Hi there,
Just for reference, what version of Mirror are you using?
For starters, I would recommend removing the deprecated version completely. When you test the other two versions, I would recommend only attaching one component at a time, not enabling/disabling the components. If they are tied into C# events or certain callbacks, they may running some code when the script is disabled.
Let me know what happens if you remove all of the NetworkTransforms except the NetworkTransform (Reliable) and ee what happens. That will limit the number of problems that could occur and help us debug this.

it shows : 89.0.0

& about Adding other Components to Player Prefab are : Network Transform ( script ) (Deprecated) + Network Transform ( Unreliable) + Network Transform ( Reliable) . I used this after When I spotted that issues. Before Was using only Network Transform ( script ) (Deprecated),
Later on I tried even Switching to Network Transform ( Reliable)

Asset Name : (VIS2K) Mirror

Observed one more thing is : From the Transform Category I found The Property Scale Is working only the Rotation + Position are Locked

after 5 hours of checking I think I have Figured it out by checking the details of Network Transform( reliable)

I just needed to Uncheck those Boxes of Sync Position + Sync Rotation which are under the Category of Header named as Selective Sync Don’t change these at Runtime .

Uncheck the Box

I should have red those stuff Earlier
:sweat_smile:

1 Like

nope, that’s was not the solution, well again I checked now I think I got the Right solution, I have Checked back those Boxes

and Changed one setting in Prefabs in the Network Transform (Reliable) Script Heading named Sync Settings under that Sub-heading named Sync Direction changed from " Client To Server " switched to " Server To Client ".

switched to

Server To Client

after doing that my Spawning objects movements are Sync on both Windows ( RUN & Build , also in Editor Windows).

still please tell me I am Right, if wrong please Correct me because changing Client to Server will leads to disaster as player wont able to communicate or ask with server

but it seems the problem still persist when I make Host in Run& Build windows the character transform get freeze, until unless I again switch it back to Client to Server

Conclusion: I Failed to Solve, Need advice from the Experts, PLease Help :frowning:

So in the lecture we use server authoritative network transform. So leave the sync direction as “Server to Client”.

Since the server has authority, if you move an object in the client, I would not expect the object to move on the server. In order to maintain the same game state in all instances of the game, we can only sync this in one direction.

In the next lecture we setup it up so the client sends a message to the server asking if it can move a unit to a certain location. The server will verify that and then control the movement and have the player move back to location, then sync that movement back to the client. This works for our RTS game where you are instructing units where to move, and then they are moving.

Try completing the “Moving Our Player” lecture, and let me know how that goes.

well in script " hasAuthority" giving me trouble,
also checked using as HadAuthority.

to use it in proper way I am forced to use private bool hasAuthority;

using Mirror;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class PlayerMovement : NetworkBehaviour
{
    [SerializeField] private NavMeshAgent agent = null;

    private Camera mainCamera;
    //private bool hasAuthority;

    #region Server

    [Command]
    private void CmdMove(Vector3 position)
    {
        if (!NavMesh.SamplePosition(position, out NavMeshHit hit, 1f, NavMesh.AllAreas ))
        {
            return;
        }

        agent.SetDestination(hit.position);
    }
    #endregion

    #region Client

    public override void OnStartAuthority()
    {
        mainCamera = Camera.main;
    }

    [ClientCallback] //[prevent from running this method everytime
    private void Update()
    {
        if (!hasAuthority ) { return; }

        if (!Input.GetMouseButtonDown(1))  {  return; }

        Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }

        CmdMove(hit.point);


    }





    #endregion
}

also facing as Error When tried to make Host In Run&Build wondow

I believe they replaced HasAuthority with IsOwner in newer versions of Mirror.

1 Like

well In tutors project’s both player ( editor + build &run window) moves Player 1 & player 2 respectively, but in my case, the non-Host player never moves. no matter I which I make Editor or Run&Build window as a Host. Always Player 1 moves

Okay, I think drop your project in here and I will take a look:
https://gdev.tv/projectupload

I have Deleted the lib before making it as Zip file.

Hi there,

Default setup: NetowrkTransform SyncMode: Client to Server
I have downloaded your project and I think everything is working as expected. Whoever is in the editor, is able to move their own player, but not the other player. So if the Host is in the editor, then I can drag Player 1 around in the scene and it syncs to the Client. If the Client is in the editor, I can drag Player 2 around in the scene and it syncs to the Host.

The only issue is that the Host doesn’t seem to be able to control the client. I.e., when I host in the editor, I can’t drag player 2 around in the scene. This actually makes sense if you have client authority over the movement.

Addtional setup: NetowrkTransform SyncMode: Server to Client
If we change to Server to Client sync mode on the NetworkTransform, the Client can now not move any of the players, but the Host can move both players. This is probably the setting you will want for the course, as we control all motion from the Server, and the Clients simply send a location to the Host where they want their units to move to.

I think since the course came out, Mirror has cleaned up authority on the NetworkTransform. I think this new version actually makes more sense by default. So don’t worry if this doesn’t match the Video exactly. You should still be able to continue with the course. If you have any trouble, just post in the forums and I’ll be here to walk you through anything.

Hope that helps, sorry for the delay in getting this worked out.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms