Add VRCPlayerAPI.IsLeaving
DrBlackRat
Issue:
Not too long ago players who are currently leaving have been made valid when using the
VRCPlayerAPI.IsValid()
check. While this allows using them during OnPlayerLeft
etc, it has made knowing when you are dealing with a leaving player a lot more difficult.When you are for example manually checking who to move ownership of a system to, you have to cache your self that this player is in the process of leaving in
OnPlayerLeft
.Suggestion:
Add a
VRCPlayerAPI.IsLeaving
check, this should return true if this player is currently in the process of leaving the instance and false if not.This should allow making systems like thew following easier to implement;
public override void OnPlayerLeft(VRCPlayerApi player)
{
leavingPlayer = player;
}
/// <summary>
/// Returns the <see cref="VRCPlayerApi"/> of a whitelisted player in the instance.
/// Useful for getting a player to move ownership of an object to.
/// </summary>
/// <returns>
/// A <see cref="VRCPlayerApi"/> of a whitelisted player in the instance,
/// or <c>null</c> if none are present.
/// </returns>
public virtual VRCPlayerApi _GetPlayerInInstance()
{
var players = new VRCPlayerApi[VRCPlayerApi.GetPlayerCount()];
VRCPlayerApi.GetPlayers(players);
foreach (var player in players)
{
if (!player.IsValid()) continue;
if (!_IsPlayerWhitelisted(player)) continue;
if (player == leavingPlayer) continue;
return player;
}
return null;
}
Log In
DrBlackRat
Just to add some clarification, this flag should be set to true
before
any OnPlayerLeft
calls have been made.Ideally, I want this so that if one system is triggering some logic due to a player leaving, another system that hasn't received the
OnPlayerLeft
call yet can still know that said player is leaving. This would allow it to, for example, ignore them when making requests to get another player.Right now, I work around this by just passing a
playerToExclude
around, which is not ideal...