-
Notifications
You must be signed in to change notification settings - Fork 450
feat!: GlobalObjectIdHash to replace PrefabHash and PrefabHashGenerator #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
internal ulong GlobalObjectIdHash64; | ||
internal ulong GlobalObjectIdHash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per @TwoTenPvP's suggestion, we're dropping 64 suffix here and simplifying its name because ulong
makes it obvious already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to leave a comment next to (above or to the side) that explains the data source that the hash was derived from?
// GlobalObjectIdHash is derived from the following pattern: (PrefabPath) : (GlobalObjectId Guid)
Or...something to that nature?
Just thinking it could be useful to have that when trying to figure out how this new pattern works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not derived from {PrefabHash}:{GlobalObjectId} pattern, it's literally just the GlobalObjectId being hashed and that's it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I see the removal of the ValidateHash and the usage of the UnityEditor.GlobalObjectId.
Makes sense!
/// <summary> | ||
/// Whether or not this is a player prefab | ||
/// </summary> | ||
public bool IsPlayer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth the breaking change to rename this from PlayerPrefab to IsPlayer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var variable1 = somePrefabReference.Prefab;
var variable2 = somePrefabReference.PlayerPrefab;
// guess what `variable1` and `variable2` mean and what are the differences
vs
var variable1 = somePrefabReference.Prefab;
var variable2 = somePrefabReference.IsPlayer;
// guess what `variable1` and `variable2` mean and what are the differences
@@ -239,48 +239,27 @@ private void OnValidate() | |||
NetworkLog.LogWarning($"{nameof(NetworkPrefab)} [{i}] does not have a {nameof(NetworkObject)} component"); | |||
} | |||
} | |||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
So as I was wondering "I wonder why we didn't just do it this way before", I am reminded that there is a use case where one would want to manually enter in that hash string, which is where you might want to have 2 different prefabs hash to the same value to support having the client and server have their own prefabs. My questions are (@TwoTenPvP pls chime in)
|
} | ||
#endif | ||
|
||
internal void ValidateHash() | ||
{ | ||
if (string.IsNullOrEmpty(PrefabHashGenerator)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my comment, assuming there is in fact a reason a user might want to force-choose a hash, we could change the default to be null, but still allow them to "expert mode" override it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have 2 questions:
- what is the user-need?
- should we serve that need with
PrefabHashGenerator
string?
to me, even if the user-need is justified and we think it's important enough and valid to keep around, I wouldn't serve/satisfy that user-need with PrefabHashGenerator
string implementation — it'd be an implementation on its own, relying on top of this infrastructure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too would be curious to know what the use case for having two different prefabs that translate to the same hash but could be different assets? (the last part I am assuming would be the only scenario to consider for this condition to be useful)
The only scenario where this could be useful (IMO) would be to have different assets per platform (i.e. mobile vs console typically have vast deltas between assets). Under this scenario, I could see where being able to directly assign the Prefab hash could be useful if you had no other "good options" that were minimal effort for the desired result.
If this is the only reason for having two different prefabs with the same prefab hash, then this might be another "pro Addressables" scenario that could solve for this type of situation.
Otherwise, for a near future solution I am sure we could figure out some pattern to handle having a way to "link GlobalObjectIdHash" values together. Maybe something like a new MLAPI aware component (i.e. "NetworkPrefabLink") that could be applied to a GameObject inside of a "master prefab" asset. You could then add as many prefabs as you wanted as children under the root GameObject containing the NetworkPrefabLink component. From there, linking the prefabs and the logic to determine which prefab to use could be completely customizable by the user. The GlobalObjectIdHash of the "master prefab" would then become the GlobalObjectIdHash for any of the prefabs defined within it.
That is one way we could approach any potential breaking features/intended functionality while also providing a more expansive/modular pattern to the users at the same time. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing 3 completely separate features here:
- Network Object
- Network Prefab
- Network Addressable
we're going to have the first 2 and leave the 3rd for later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks clean, no objections, but before merging I'd like to make sure the 'force a hash' case is no longer desired
Yes. This was a supported usecase, either server specific prefabs or separate projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
Like the consolidation of the GlobalObjectHashId and related updates.
Based on Albin's response, it would seem it was for a similar type of situation as I outlined above where there could be differences in assets (due to platform or even potentially version) that have the same prefab hash.
To solve for this we can just implement something like the NetworkPrefab that will be able to handle this scenario.
we're replacing
PrefabHash
andPrefabHashGenerator
string withGlobalObjectIdHash
.