First time messing with System.Guid's so may be struggling due to ignorance. This is Networking related but not directly involving Networking so posting here.
I have this ScriptableObject setup im messing with where I want a unique guid stored on each one
public abstract class ScriptableNetworkObject<T> : ScriptableNetworkObject where T : ScriptableNetworkObject<T>
{
[NonSerialized] private static Dictionary<Guid, T> dict = new Dictionary<Guid, T>();
[SerializeField]
byte[] m_Guid;
public override Guid Guid => new Guid(m_Guid);
private void Awake() => Try();
private void OnEnable() => Try();
private void OnValidate() => Try();
private void Try()
{
Debug.Log(name + " is trying!" + " (" + Guid + ")");
TryCreateGuid();
TryRegister();
}
private void TryCreateGuid()
{
if (Application.isPlaying) return;
if (m_Guid == null || m_Guid.Length == 0)
m_Guid = Guid.NewGuid().ToByteArray();
}
private void TryRegister()
{
if (!dict.ContainsKey(Guid))
{
Debug.Log("Registering Item: " + name + " (" + Guid + ")");
dict.Add(Guid, this as T);
}
else if (dict[Guid] != this)
{
Debug.Log("Item: " + name + " Already registered!" + " (" + Guid + ")");
if (!Application.isPlaying)
{
m_Guid = Guid.NewGuid().ToByteArray();
TryRegister();
}
}
}
As far as I can see the byte arrays on all of the Items im testing are unique in editor but in build the Guid property here used in the dict is logging as identical for all of my Items? Not sure if this is something weird with serialization or guids or what