Hi There,
The most common reason for the unit list to not be populated is copy and pasting the event subscription code, and not making the correct changes.
Please make sure you have “+” or “-” in all the right spaces as well as spawned or despawned in the correct places as well.
public override void OnStartServer()
{
Unit.ServerOnUnitSpawned += ServerHandleUnitSpawned;
Unit.ServerOnUnitDespawned += ServerHandleUnitDespawned;
public override void OnStopServer()
{
Unit.ServerOnUnitSpawned -= ServerHandleUnitSpawned;
Unit.ServerOnUnitDespawned -= ServerHandleUnitDespawned;
You have probably seen this already based on your post, but thought I would double check.
Next thing to check is if ServerHandleUnitSpawned is being called. Have you placed a debug.log statement in there to check if it’s being called?
I think later in the course we change the code anyway. My version has OnStartAuthority() instead of OnStartClient(), with no extra checks. If you want you can just change it to this now, as we will do this later anyway in the course.
public override void OnStartAuthority()
{
AuthorityOnUnitSpawned?.Invoke(this);
}