Can´t move client, netcode for gameobjects.

Hii, i’m investigating netcode for gameobjects and doing a test I can’t move the client player. When I connect to the server, the “EmptyPrefab” only has the component networkobject, in order to spawn one player or another (classes etc), I have done it with this code;

public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();

clientID = (int)OwnerClientId;

if (IsOwner)
{
player = SpawnPlayer();
}

}

// Update is called once per frame
public GameObject SpawnPlayer()
{
GameObject[ ] spawnPoints = GameObject.FindGameObjectsWithTag(“SpawnPoint”);

GameObject go = Instantiate(player, spawnPoints[Random.Range(0, spawnPoints.Length - 1)].transform.position, Quaternion.identity);
go.GetComponent().SpawnWithOwnership(OwnerClientId);

return go;
}

In the spawned player i did just this only to test :

private void Update()
{

GetComponentInChildren().enabled = true;
GetComponentInChildren().enabled = true;
GetComponent().enabled = true;
GetComponent().enabled = true;
}

I added the ClientTransformNetwork and nothing happens, i can’t even move the character in the client itself, does anyone know what might be happening? Ty.

Any error messages in the Console window?
SpawnPlayer must be run on the server. The IsOwner check seems inadequate if this script runs on an object that is spawned for every client since you cannot spawn on clients.
Please add more context since its impossible to tell which script on which object each of these methods run on. And use code tags.

I was able to fix it by changing CanCommitToTransform (On NetworkTransform) to false and when spawning the player change CommitToTransform to true if IsOwner.

“The IsOwner check seems inadequate if this script runs on an object that is spawned for every client since you cannot spawn on clients.” Yes, I have changed it to if (isServer).

I don’t know if it will be the best solution of all but at least now it works. Thank you :slight_smile:

use client network transform instead of just network transform

1 Like