How can I use The OnNetworkTransformStateUpdated virtual method in the network transform component?? The problem is this method is protected, means I cannot subscribe any other method to this because of it’s protection level. I also tried overriding this method like this:
using Unity.Netcode;
using Unity.Netcode.Components;
using UnityEngine;
public class CustomNetworkTransform : NetworkTransform
{
Vector3 LastMyPositionFromServer;
[SerializeField] NetworkObject networkObject;
// Override the OnNetworkTransformStateUpdated method to apply the manipulated position
protected override void OnNetworkTransformStateUpdated(NetworkTransformState state)
{
if (networkObject.IsOwner)
{
LastMyPositionFromServer = state.position;
if (Vector2.Distance(new Vector2(LastMyPositionFromServer.x, LastMyPositionFromServer.y), new Vector2(transform.position.x, transform.position.y)) > 1.5f && !IsServer)
{
transform.position = LastMyPositionFromServer;
}
}
else
{
transform.position = state.position;
}
}
}
but it’s probably also not allowed by unity as it throws this error :
Assets\scripts\CustomNetworkTransform.cs(11,29): error CS0115: ‘CustomNetworkTransform.OnNetworkTransformStateUpdated(NetworkTransform.NetworkTransformState)’: no suitable method found to override
The official document on this method only contains this and DON’T guide how to use and implement it:
“NetworkTransform.OnNetworkTransformStateUpdated: This virtual method is invoked when the non-authoritative instance is receiving a pushed NetworkTransformState update from the authoritative instance. This can be used to better determine the precise values updated to non-authoritative instances for prediction related tasks.”
I am just surfing the internet and suffering but didn’t find any relavent information.
Can someone Please tell me how can i use this method?