CamC
Normal2y ago
Cam

GUIDManager

I posted a very old version of this a long time ago (https://canary.discord.com/channels/393839515074297858/677646675560366141/981127682437836812) but have improved this script a lot over time and figured I would share a much better version of it until we get some official GUID component. This is intended for you to add a GUID int to your model, syncing it on start, and registering it to the GUIDManager's dictionary. Using it is extremely simple, let's say you had a
Ball
component reference you wanted to sync, first you'd make your ball component either derive from the simple GUIDModel pre-implemented one, or simply add your own int to your existing model (Check GUID model for how to set it up in OnRealtimeModelReplaced). Then in some other script that wants to send a reference to the ball, simply send the GUID of it (Typically
ball.GUID
as the ID reference), then when it is received on your local or remote client, simply do
GUIDManager.FetchComponent<Ball>(guidOfBall)
or alternatively
GUIDManager.TryFetchComponent(guidOfBall, out Ball ball)
if you prefer the bool return type for if it was found in the dictionary. My old implementation used to use strings of GUIDs to send for reference but I found this was very inefficient and changed it over entirely to ints. ints are 4 bytes compared to the GUID string being about 80, dictionary lookup hashing is literally free as the int is it's own hashcode, and many other efficiencies are gained over strings, and still allows for about 4 billion entries which is a crazy high amount.
Hopefully you get some use out of this and find it useful :)
Was this page helpful?