Step 7 — Removing avatars

Previous steps have just added new avatars to the scene, but if a user logs out, the corresponding avatar stays as an unmovable zombie. This step fixes this.

When a user leaves the scene, the BSCollaborate node sends out a hasLeft event. We respond to this event by simply removing the AvatarInfo node of this user from the GrAvatars Group node. Afterwards the BSCollaborate node will remove the UserData node it has just sent us from its users field and the reference count based garbage collection in BS Contact will delete the AvatarInfo node. Therefore it is important that we do not keep any other references to the AvatarInfo or UserData node. This is, however, not unique to BS Collaborate as any node must have no reference in order to be deleted.

While our script just removes an avatar from the scene, more elaborate applications can play an animation on the avatar and remove it from the GrAvatar Group node after the animation has finished. It can even make the animation dependent on the value of the loginState field on the UserData node and thus visualize whether the user logged out gracefully, had a connection drop, etc.