So I have been getting problems with Netcode.
Originally there were only issues with a skipping mechanic, but I noticed its worse than that.
- Bug/Issue:
I´m getting even weirder bugs:
public void PlayerWantsToSkipTurn()
{
if (GetOwnership() && IsClient)
{
Debug.Log("Client " + IsClient + "; Server " + IsServer + "; Host " + IsHost);
SetSkipStateServerRpc();
//if (GetWantsToSkipState() && !unitsThatWantToEndTurnList.Contains(this))
//{
// foreach (Unit unit in LevelGrid.Instance.GetAllUnitList())
// {
// unit.AddWantsToSkipList(this);
// }
//}
//if (!GetWantsToSkipState() && unitsThatWantToEndTurnList.Contains(this))
//{
// foreach (Unit unit in LevelGrid.Instance.GetAllUnitList())
// {
// unit.RemoveWantsToSkipList(this);
// }
//}
//while (beforechangeWantsToSkipState == GetWantsToSkipState())
//{
//}
foreach(Unit teamTurnUnits in LevelGrid.Instance.GetTeamTurnUnits())
{
if (teamTurnUnits.GetWantsToSkipState())
AddWantsToSkipList(teamTurnUnits);
if(!teamTurnUnits.GetWantsToSkipState())
RemoveWantsToSkipList(teamTurnUnits);
Debug.Log(teamTurnUnits.GetWantsToSkipState() + "|Actually:" + GetWantsToSkipState());
}
Debug.Log(unitsThatWantToEndTurnList.Count);
CheckEndTurnUnits();
}
}
The Rpc isn´t even getting called anymore, what is happening?
On the Host it works, but not on the Client and I checked with Debug.Log()
.
Its even worse, somehow there is no error like that you can´t call an ServerRpc as a Server, no errors but it just never gets to run why is that?
This is the ServerRpc:
[ServerRpc(RequireOwnership = false)]
private void SetSkipStateServerRpc()
{
Debug.Log("1. " + wantsToSkip.Value);
wantsToSkip.Value = !wantsToSkip.Value;
Debug.Log("2. " + wantsToSkip.Value);
}
- Bug/Issue:
I have wrote a Mineplacement Script and all worked fine but then:
public override void TakeAction(GridPos gridPos, Action onActionComplete)
{
if (!IsClient) return;
ActionStart(onActionComplete);
this.placePos = LevelGrid.Instance.GetWorldPos(gridPos);
clonedObj = Instantiate(placeObj, placePos, Quaternion.identity);
//PlaceMineServerRpc();
teamTurnId = GetComponent<Unit>().GetCurrentTeamId();
PlaceMineServerRpc();
//HideMineClientRpc();
}
So kind of the same thing, on the host all workes fine but not on the Client, as I wrote it I made a ServerRpc so that both, the Host and the Client can place them on the Network. But everytime I run it, it says something like: NullReferencExeption for the clonedObject but it is saved into a Variable:
private GameObject clonedObj;
Probably I did something wrong, with the Code, maybe its all some error outside the code and more like configuration error. So if anybody can help me, I would appreciate it.
Details:
I am using Unity 2021.3.16f, I know that there is a newer version but I didn´t bothered updating.
I think I am using the newest version of Netcode: 1.1.0