Skip to content

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

Merged
merged 17 commits into from
Apr 8, 2021

Conversation

0xFA11
Copy link
Contributor

@0xFA11 0xFA11 commented Apr 1, 2021

we're replacing PrefabHash and PrefabHashGenerator string with GlobalObjectIdHash.

internal ulong GlobalObjectIdHash64;
internal ulong GlobalObjectIdHash;
Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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 :)

Copy link
Collaborator

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!

@0xFA11 0xFA11 marked this pull request as draft April 1, 2021 20:37
/// <summary>
/// Whether or not this is a player prefab
/// </summary>
public bool IsPlayer;
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@mattwalsh-unity
Copy link
Contributor

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)

  • does this 'deliberately making 2 prefabs have the same hash' pattern actually work / have been successfully used? If this was just a musing on how one might solve this (real) problem (because IIRC you would then need to write custom code to support it) then cool. Else, we need to have a conversation about the impact on customers / how to deal with that.

}
#endif

internal void ValidateHash()
{
if (string.IsNullOrEmpty(PrefabHashGenerator))
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have 2 questions:

  1. what is the user-need?
  2. 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.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity Apr 2, 2021

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. :)

Copy link
Contributor Author

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:

  1. Network Object
  2. Network Prefab
  3. Network Addressable

we're going to have the first 2 and leave the 3rd for later.

Copy link
Contributor

@mattwalsh-unity mattwalsh-unity left a 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

@0xFA11 0xFA11 marked this pull request as ready for review April 2, 2021 12:51
@TwoTenPvP
Copy link
Contributor

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)

  • does this 'deliberately making 2 prefabs have the same hash' pattern actually work / have been successfully used? If this was just a musing on how one might solve this (real) problem (because IIRC you would then need to write custom code to support it) then cool. Else, we need to have a conversation about the impact on customers / how to deal with that.

Yes. This was a supported usecase, either server specific prefabs or separate projects.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a 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.

@0xFA11 0xFA11 enabled auto-merge (squash) April 8, 2021 15:06
@0xFA11 0xFA11 merged commit 186c31d into develop Apr 8, 2021
@0xFA11 0xFA11 deleted the feature/prefabhash-to-gobjid branch April 8, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants