Custom network transform only recognizing new position from the host

Hello!!!

Recently I decided to make my own network transform component to compensate for the lagginess.

Code:

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

[NetworkSettings (channel = 0, sendInterval =  0.033f)]
public class NetworkTransformSync : NetworkBehaviour {

	public bool syncPosition;
	public bool syncRotationY;
	[SyncVar]
	private Vector3 syncPos;
	[SyncVar]
	private float syncRotY;
	public float lerpRate;
	
	void Update () {
		TransmitSync ();
	}
	
	void FixedUpdate () {
		LerpTransform ();
	}
	
	void LerpTransform () {
		if (!isLocalPlayer)
		{
			transform.position = Vector3.Lerp (transform.position, syncPos, lerpRate * Time.deltaTime);
			transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, syncRotY,  0), lerpRate * Time.deltaTime);
		}
	}
	
	[Command]
	void CmdSyncTransform () {
		if (syncPosition)
		{
			syncPos = transform.position;
		}
		if (syncRotationY)
		{
			syncRotY = transform.rotation.y;
		}
	}
	
	[ClientCallback]
	void TransmitSync () {
		if (isLocalPlayer)
		{
			CmdSyncTransform ();
		}
	}
}

My only problem is, it only syncs positions to the host. The server does not receive positions and as a result thinks the player is always at 0 0 0. Help?

Hi,

Thanks for the part of code. This help me so much for my dev.
Hope this help !

using UnityEngine;
using UnityEngine.Networking;
 
[NetworkSettings (channel = 0, sendInterval = 0.04f)]
public class NetworkTransform_Custom : NetworkBehaviour {
	
    public float lerpRate;
    [SerializeField]
    Transform playerPrefab;
    [SerializeField]
    Transform playerCamera;

    [SyncVar]
    private Vector3 syncPos;

    [SyncVar]
    private float syncRotY;

    [SyncVar]
    private float syncRotX;


    void Update ()
    {
        TransmitSync ();
    }
     
    void FixedUpdate ()
    {
        LerpTransform ();
    }
     
    void LerpTransform ()
    {
        if (!isLocalPlayer)
        {
            playerPrefab.position = Vector3.Lerp (playerPrefab.position, syncPos, lerpRate * Time.deltaTime);
            playerPrefab.rotation = Quaternion.Lerp (playerPrefab.rotation, Quaternion.Euler (0, syncRotY,  0), lerpRate * Time.deltaTime);

            playerCamera.rotation = Quaternion.Lerp (playerCamera.rotation, Quaternion.Euler(syncRotX, playerCamera.rotation.eulerAngles.y, 0), lerpRate * Time.deltaTime);
        }
    }
     
    [Command]
    void CmdSyncTransform (Vector3 pos, float rotY, float rotX)
    {
        syncPos = pos;
        syncRotY = rotY;
        syncRotX = rotX;
    }
     
    [ClientCallback]
    void TransmitSync ()
    {
        if (isLocalPlayer)
        {
            CmdSyncTransform (playerPrefab.position, playerPrefab.rotation.eulerAngles.y, playerCamera.rotation.eulerAngles.x);
        }
    }
    
}

For connection issues, make sure your ports are opened.