Unit Selection doesn't work for Client

Hi!
Already check out the similar thread here. The solution didn’t work for me. All events in RtsPlayer script are fine, but myUnits list is still empty for the client. Can’t figure out why(( Any suggestions are welcome :slight_smile:

EDIT: For some reason checks “(!isClientOnly || !hasAuthority)” in OnStartClient() and probably OnStopClient() methods in Unit.cs didn’t work for me. I removed them for a time being, but if anyone knows why they didn’t work please share :slight_smile:

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);
}

Thank you! Everything works like a charm :slight_smile:
Sorry for the late reply and happy holidays!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms