How to let the client move the server`s objects?

There is an object in a scene called P1 with a “Network object” and “Network Transform” components on it.

using Network Manager I spawn a prefab of an object that has this script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;

public class ControllP1 : NetworkBehaviour
{

    [SerializeField] private Vector3 StartPosition;
    [SerializeField] private GameObject P1;

    void Start()
    {
        P1 = GameObject.Find("P1");
    }

    void Update()
    {

        if (Input.GetKeyDown(KeyCode.R))
        {
            RestartCharacterPositionRpc();
        }
 
    }

    [Rpc(SendTo.Server)]
    void RestartCharacterPositionRpc()
    {

        P1.transform.position = StartPosition;

    }

}

When the host presses the button P1 object position is set to StartPosition. However, when the client presses the button, nothing happens.

When you spawn it you can‘t use Find in Start. Find by string is brittle anyway, it‘s likely to be called „P1(Clone)“ after instantiating. And in Start it may not have been spawned yet.

When you spawn it, either the P1 object tells other local scripts that it was spawned, or the server sends an Rpc to clients with the spawned object‘s NetworkObjectId so that they can look it up in NetworkManager.Singleton.SpawnManager.SpawnedObjects[id] (from the top off my head, names may be similar)

I played a little bit with the project today and understood the problem. The client could not send Rpc to the server! And it could not do it, because it did not connect to the server (I saw it when I enabled the devlogs in the network manager). I backuped the project, remade the scene setup and scripts and now it is working well, even tho it is almost identical to the original project.

I do not know why I initially got the problem. Maybe because I updated the “netcode for gameobjects” package in the middle of doing the project, maybe it is somehow correlated to this thread Client Build to Client Build Connects but Client Build to Editor Host does not .