Bad wording on the documentation for ConnectionState

/// <summary>
    /// An optional cleanup component that can be added to a newly created connection to monitor its state changes.
    /// Must be added and removed by the gameplay logic. When the <see cref="ConnectionState"/> is present, the NetCode package
    /// will update the component when the connection state changes.
    /// By adding the ConnectionState state component, the connection <see cref="NetworkId"/> and <see cref="DisconnectReason"/>
    /// are retained until the game don't remove the state component.
    /// </summary>
    public struct ConnectionState : ICleanupComponentData

“By adding the ConnectionState state component, the connection NetworkId and DisconnectReason are retained until the game don’t remove the state component.

This sentence doesn’t make grammatical sense. Until the game does what? Removes the state component? Is the correct wording: “until the game removes the state component.” Or is is “until the game [Does something]. Don’t remove the state component before the [something] occurs.” ? Please clarify and edit the documentation to correct this confusion.

I was supposed to post this in NetCode for Entities subforum…

Yeah the wording isn’t great. It should be
/// By adding the ConnectionState state component, the connection and
/// are retained until your gameplay code removes the ConnectionState component.

This is basically to allow you to detect disconnects and be able to get other info like network id and disconnect reason. A lot of this should be less useful now that we have connection events though.

Is there a sample project showing how to use connection events?

We added some as part of our 1.3 release, which should be coming soon.
In the meantime, your main entry point would be
var connectionEventsForTick = SystemAPI.GetSingleton().ConnectionEventsForTick;

Will these connection events only work if the optional ConnectionState component was added? Or is that no longer optional and is automatically added and removed now?

They are tracked separately. You don’t need a ConnectionState component present to use those events.

The. ConnectionState is pretty much deprecated. Stick with Connection Events whenever you can.
Be aware of the limitations though: because they last only for one frame, you can lose events if your system aren’t always running or cache them.
A classic example: a connection event is raised and the system that need that has a RequireForUpdate condition is not met yet.
In this case, you need to either cache the events locally in that system (and skip the remaining update part) or have another systems of yours that cache all of them and make them consumable by the application in a different way.