Skip to content

fix: client writing to netvar error #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ public class ServerCharacterMovement : NetworkBehaviour
private void Awake()
{
m_NavigationSystem = GameObject.FindGameObjectWithTag(NavigationSystem.NavigationSystemTag).GetComponent<NavigationSystem>();
// disable this NetworkBehavior until it is spawned
enabled = false;
}

public override void OnNetworkSpawn()
{
if (!IsServer)
if (IsServer)
{
// Disable server component on clients
enabled = false;
return;
}
// Only enable server component on servers
enabled = true;

// On the server enable navMeshAgent and initialize
m_NavMeshAgent.enabled = true;
m_NavPath = new DynamicNavPath(m_NavMeshAgent, m_NavigationSystem);
// On the server enable navMeshAgent and initialize
m_NavMeshAgent.enabled = true;
m_NavPath = new DynamicNavPath(m_NavMeshAgent, m_NavigationSystem);
}
}

/// <summary>
Expand Down Expand Up @@ -177,6 +178,12 @@ public override void OnNetworkDespawn()
{
m_NavPath.Dispose();
}
if (IsServer)
{
// Disable server components when despawning
enabled = false;
m_NavMeshAgent.enabled = false;
}
}

private void PerformMovement()
Expand Down