Skip to content

feat: Added a way to safely access GlobalObjectIdHash via PrefabHashId [MTT-1645] #2437

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
Mar 22, 2023

Conversation

samlucas-unity
Copy link
Contributor

Added a way to access the GlobalObjectIdHash for use in ConnectionApproval callback. It checks the Object is actually a prefab before returning the value.

ConnectionApproval Runtime Determined GlobalObjectIdHash Spawn Not Possible [MTT-1645]

Changelog

  • Added a way to access the GlobalObjectIdHash via PrefabHashId for use in the Connection Approval Callback.

NetworkMetrics were tracking named message received events but it is possible for message handlers to unregister themselves.
We now cache the name of the message handler before invoking it so the Network Metrics can access the name even if its removed.
@samlucas-unity samlucas-unity requested a review from a team as a code owner March 7, 2023 15:53
}
}

if ( NetworkManager.PrefabHandler.ContainsHandler( GlobalObjectIdHash ) )
Copy link
Collaborator

Choose a reason for hiding this comment

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

The standards check issues are due to the 2 whitespaces on line 36 position 21 and line 36 position 67.
if (NetworkManager.PrefabHandler.ContainsHandler( GlobalObjectIdHash ))
👍

{
get
{
foreach (var prefabList in NetworkManager.NetworkConfig.Prefabs.NetworkPrefabsLists)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we cache the result of this so it doesn't have to do this for-loop every time it's accessed? This seems like it would be pretty expensive, but as a property, it's not obvious that it's expensive to access.

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 don't think we can unfortunately. I've added some tests and this code isn't correct. There is a Prefabs list in NetworkManager.NetworkConfig.Prefabs.Prefabs which is the actual list of prefabs we need to chefck against. NetworkPrefabsLists is just the list of saved prefabs, any prefabs added at runtime won't be considered. Since that list can change we can't rely on a cached value. Fortunately the use case for this is limited to the ConnectionApproval callback so its unlikely its going to get hit very often. I will update the PR soon with those changes.

samlucas-unity and others added 7 commits March 13, 2023 12:01
and not the saved NetworkPrefabsLists as they opnly contain saved prefabs.
Also removed checking the PrefabHandler as this isn't correct.
Updating the test for this PR.
@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) March 22, 2023 19:38
removing System.Collections that is not used
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