So i followed along and now have a problem where in the editor if im the server, each player will have a building in myBuildings list as intended, but when i run the Client the myBuildings list adds the same building 4 times.
I have tried to go through the code all the way from the point a building is added on the client side list, but can only see that it is called once. Anyone who maybe can help point out my mistake?
Picture of the problem:
Only supposed to have a base and resource generator in the list as they are the only 2 buildings the player has.
RTSPlayer client code looks like this.
public override void OnStartAuthority()
{
if (NetworkServer.active) { return; }
Unit.AuthorityOnUnitSpawned += clientHandleUnitSpawned;
Unit.AuthorityOnUnitDeSpawned += clientHandleUnitDeSpawned;
Building.AuthorityOnBuildingSpawned += clientHandleBuildingSpawned;
Building.AuthorityOnBuildingDeSpawned += clientHandleBuildingDeSpawned;
}
public override void OnStopClient()
{
if (!isClientOnly || !hasAuthority) { return; }
Unit.AuthorityOnUnitSpawned -= clientHandleUnitSpawned;
Unit.AuthorityOnUnitDeSpawned -= clientHandleUnitDeSpawned;
Building.AuthorityOnBuildingSpawned -= clientHandleBuildingSpawned;
Building.AuthorityOnBuildingDeSpawned -= clientHandleBuildingDeSpawned;
}
private void clientHandleBuildingSpawned(Building building)
{
myBuildings.Add(building);
}
private void clientHandleBuildingDeSpawned(Building building)
{
myBuildings.Remove(building);
}
Building Auth call:
public override void OnStartAuthority()
{
AuthorityOnBuildingSpawned?.Invoke(this);
}
public override void OnStopClient()
{
if (!hasAuthority) { return; }
AuthorityOnBuildingDeSpawned?.Invoke(this);
}
On the server side everything works as it should.