Remove User Caching from UserFrame / UserTracker

Is it possible to remove the caching from the UserTracker / UserFrame data? I really need to map certain values directly to the order of users entering the frame instead of the current Id tracking implementation.

What I want is:

  • User 1 enters the frame, receives Id 1 (color Yellow)
  • User 2 enters the frame, receives Id 2 (color Red)
  • User 1 leaves the frame
  • User 2 takes over Id 1 (color switch to Yellow)
  • User 2 leaves the frame
  • User 2 re-enters the frame, receives Id 1 (color Yellow)
  • User 1 re-enters the frame, receives Id 2 (color Red)

What happens is:

  • User 1 enters the frame, receives Id 1 (color Yellow)
  • User 2 enters the frame, receives Id 2 (color Red)
  • User 1 leaves the frame
  • User 2 keeps Id 2 (no color switch)
  • User 2 leaves the frame
  • User 2 re-enters the frame, receives Id 2 (cache!) (color Red)
  • User 1 re-enters the frame, receives Id 1 (cache!) (color Yellow)

The caching is super apparent because it still exists even after stopping the current game and restarting it (in editor). As soon as a player recieves an Id, it will keep receiving that same Id for the rest of the session (until I close the editor).

The problem that I have is that all the provided userFrame solutions (for instance the Segmentation) are fully built around the Id’s. This means that if User 2 leaves the screen and re-enters it as the sole user, it still receives the Red color (as that one is hard-wired to Id2) in the provided scripts.

I can of course manually remap the Id’s to the order, except this needs to be done every frame, which is a HUGE overhead that is completely unneccesary if I can just disable the internal caching of the Id’s.

I’ve created a workaround for this:

  • I populate a List with the received Ids both the OnNewUserEvent and OnLostUserEvent
  • This list is an representation of the index order of the User Ids (i.e. if index 0 leaves, index 1 becomes index 0, as is the default behaviour of Lists)
  • I convert this list to a Dictionary using the Id as Key and the index in the List as Value
  • I use both the List and the Dictionary as a reference for managing my own User distribution

The Dictionary can be used in a modified version of the Segment2Texture ComputeShader for instance, where a remapped interger Array can be used to map the Ids within the ComputeShade to their corresponding indexes. This way the P2 receives the color of P1 as soon as P1 leaves the screen.