Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.1k stars 430 forks source link

MPPM: allow scripts to determine if we're running as a virtual player #2865

Open CodeSmile-0000011110110111 opened 2 months ago

CodeSmile-0000011110110111 commented 2 months ago

Is your feature request related to a problem? Please describe.
Some code shouldn't be run in a virtual player, if only for convenience. 

Most urgently: editor tools that pop up a window where you'd only want that window open in the main editor. You may not even know which editor the window belongs to and make the edits in the wrong place. A virtual player may also overwrite the same configuration file of an editor tool. 

Virtual players may also run InitOnLoad code intended to run only when the project is "opened for the first time". This may just slow down opening the editor but could also lead to issues. Again, would be helpful to be able to safeguard against this.

Describe the solution you'd like
A simple bool property like:
CurrentPlayer.IsVirtualPlayer
and correspondingly:
CurrentPlayer.IsMainEditor

Describe alternatives you've considered
Alternative? Reflection. So many things seem readily available in Multiplayer Playmode classes but nothing is public besides the tags.