-
Notifications
You must be signed in to change notification settings - Fork 450
refactor!: NetworkPrefabHandler and INetworkPrefabInstanceHandler API & XmlDoc changes #977
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
refactor!: NetworkPrefabHandler and INetworkPrefabInstanceHandler API & XmlDoc changes #977
Conversation
Renamed the two methods within INetworkPrefabInstanceHandler to better reflect what their function was and to avoid user confusion. Improved comments and added additional XML Documentation for the NetworkPrefabHandler and associated INetworkPrefabInstanceHandler
NetworkObject ClientInstantiateOverride(ulong ownerClientId, Vector3 position, Quaternion rotation); | ||
|
||
/// <summary> | ||
/// Client and Server | ||
/// Once an implementation is registered with the <see cref="NetworkPrefabHandler"/>, this method will be called every time | ||
/// a Network Prefab associated <see cref="NetworkObject"/> is destroyed. | ||
/// If <see cref="NetworkObject.Despawn(bool)"/> is invoked with the default destroy parameter (i.e. false) then this method will not be invoked. | ||
/// | ||
/// Note on Pooling: When invoked, you do not need to despawn or destroy the NetworkObject as long as you want your pool to persist. | ||
/// The most common approach is to make the <see cref="NetworkObject"/> inactive by calling <see cref="GameObject.SetActive(bool)"/>. | ||
/// </summary> | ||
/// <param name="networkObject">The <see cref="NetworkObject"/> being destroyed</param> | ||
void DestroyOverride(NetworkObject networkObject); |
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 not sure if I'd go for ClientInstantiateOverride
& DestroyOverride
instead of HandleNetworkPrefabSpawn
& HandleNetworkPrefabDestroy
under an interface called INetworkPrefabInstanceHandler
.
I think I'd drop "-Override" suffix and keep "Handle-" prefix around.
Also "Client-" prefix sounds a little risky to me in terms of our future potential and its API-breaking nature.
We might expand this feature's impact area and even make it work for both client and server sides. That would require another API-breaking change just to drop "Client-" prefix or we might have to add another super similar API that starts with "Server-" prefix to not break the old API (which would not be ideal IMHO).
Only thing I'd change here would be HandleNetworkPrefabDestroy
→ HandleNetworkPrefabDespawn
to match NetworkBehaviour.OnNetworkSpawn()
and NetworkBehaviour.OnNetworkDespawn()
naming convention.
Also, it'd be tempting to keep client-specific comments around but I think they should go away and make feature non-client specific. Client-specific comment may go under NetworkPrefabHandler
since it is the source where client-specific nature is coming from (and even that might change in the future to cover both client and server side, hence my earlier comments above).
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.
So the old naming here was very inconsistent. Spawn
, Destroy
don't match. We either want HandleNetworkPrefabDespawn
or rename the Spawn
to Instantiate
.
Now the reason we want for Instantiate/Destroy
was is because you can spawn/despawn a networkobject in MLAPI without triggering these handlers (GameObject.Destroy on the server for instance skips the handler). And what they really do is override a GameObject Instatiate
/ Destroy
function and replace it with something else.
I prefer the Override
suffix over Handle
prefix. Because HandleNetworkPrefabDestroy
does not indicate whether this handler is run in addition to the destroy or instead of the destroy. Dropping the Client
prefix on InstantiateOverride
sounds good if we consider future potential.
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.
so it's:
HandleNetworkPrefabSpawn
HandleNetworkPrefabDespawn
vs
InstantiateOverride
DestroyOverride
:)
I believe it's fair to say that we'd go for Instantiate
/Destroy
.
so my final suggestion would be:
HandleInstantiate
HandleDestroy
:P
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.
HandleInstantiate, HandleDestroy sounds good to me 👍
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.
The only issue I have with "HandleInstantiate" is that this is only invoked on the client side and could be misleading. However, that can be made clear in documentation.
How about we even further simplify this? I mean it is a "Handler" so not sure we have to put "handle" in front of all of the methods. Why not:
-
Instantiate
-
Destroy
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 is only invoked on the client side
hence my first comment, it is currently client-only but we could expand it to cover both server and client.
it is a "Handler" so ...
I think that's also a fair point. INetworkPrefabInstanceHandler.Instantiate
& INetworkPrefabInstanceHandler.Destroy
it is :)
Renamed the interface methods. Updated comments. Refactored NetworkPrefabHandler to handle GitHub Issue 990 as well as made adjustments to be able to send the appropriate GlobalObjectIdHash as a host. This also includes a public facing method in the NetworkManager to be able to lookup a NetworkManager defined NetworkPrefab Override for some associated cases relating to Host mode and NetworkPrefabHandlers and NetworkPrefab Overrides. Made adjustments to the SceneTransitioning test and associated scenes and assets.
@@ -86,8 +86,7 @@ private void OnTriggerEnter(Collider other) | |||
} | |||
else | |||
{ | |||
NetworkObject.Despawn(); | |||
NetworkObject.gameObject.SetActive(false); |
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.
did we drop this intentionally?
I'm talking about NetworkObject.gameObject.SetActive(false);
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.
Review it again as I just updated.
It should make more sense...
@@ -85,6 +82,21 @@ private void RegisterCustomPrefabHandler() | |||
} | |||
} | |||
|
|||
|
|||
private void DeRegisterCustomPrefabHandler() |
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.
super-nit :)
private void DeRegisterCustomPrefabHandler() | |
private void DeregisterCustomPrefabHandler() |
Added the case where no prefab handler override is registered but there is still a host. Added a lookup table to quickly get the proper source GlobalObjectIdHash value for the NetworkPrefab that has an override in the NetworkManager. The first scene in the SceneTransitioningTest uses a NetworkManager defined prefab override, in host mode the host will pool while clients will not pool (no need since there is no way to override the instantiation) and the host will always send the source NetworkPrefab's GlobalObjectIdHash value as opposed to the target override's GlobalObjectIdHash. Fixed Fatih's super-nit-pick :)
Removing despawn replication and from places where they are no longer needed either due to the now proper message ordering. Updated the GenericNetowrkObjectBehaviour such that clients disable the MeshRenderer component and then have a delayed re-enabling of it upon being spawned in order to avoid the latent update in the transform's position (removes the flickering of NetworkObjects on the client). Added the ability to make the SwitchSceneHandler have a delayed "auto switch" in order to run cycled long burn runs to assure everything is working "as expected". Fixed an access violation in StatsDisplay ( minor thing that was bugging me).
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 a few other changes going in after I approved this PR.
I think I should re-review this again some time — please hmu when you think it's ready to be reviewed again :)
@@ -504,14 +504,14 @@ internal void ServerDestroySpawnedSceneObjects() | |||
// This **needs** to be here until we overhaul NetworkSceneManager due to dependencies | |||
// that occur shortly after NetworkSceneManager invokes ServerDestroySpawnedSceneObjects | |||
// within the NetworkSceneManager.SwitchScene method. | |||
SpawnedObjectsList.Remove(sobj); | |||
|
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 is really a short term change and will be updated in PR-955 Additive Scene Loading.
@@ -559,7 +559,10 @@ internal void DestroySceneObjects() | |||
if (NetworkManager.PrefabHandler.ContainsHandler(networkObjects[i])) | |||
{ | |||
NetworkManager.PrefabHandler.HandleNetworkPrefabDestroy(networkObjects[i]); | |||
OnDespawnObject(networkObjects[i], false); | |||
if (SpawnedObjects.ContainsKey(networkObjects[i].NetworkObjectId)) |
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.
More short term updates until PR-955.
Refactored a better client side "no blinking when spawning" solution. Fixed an issue where everyone was sending destroy messages to everyone else.
@@ -504,14 +504,14 @@ internal void ServerDestroySpawnedSceneObjects() | |||
// This **needs** to be here until we overhaul NetworkSceneManager due to dependencies | |||
// that occur shortly after NetworkSceneManager invokes ServerDestroySpawnedSceneObjects | |||
// within the NetworkSceneManager.SwitchScene method. | |||
SpawnedObjectsList.Remove(sobj); | |||
|
|||
if (NetworkManager.PrefabHandler != null && NetworkManager.PrefabHandler.ContainsHandler(sobj)) | |||
{ | |||
NetworkManager.PrefabHandler.HandleNetworkPrefabDestroy(sobj); |
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 I am leaving up to the user to handle how they want to deal with scene transitions and prefab handler overrides.
@@ -681,7 +684,6 @@ internal void OnDespawnObject(NetworkObject networkObject, bool destroyGameObjec | |||
if (NetworkManager.PrefabHandler.ContainsHandler(networkObject)) | |||
{ | |||
NetworkManager.PrefabHandler.HandleNetworkPrefabDestroy(networkObject); | |||
OnDespawnObject(networkObject, false); |
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.
@LukeStampfli , I could you double check this? I did some testing on my end and I think this is no longer needed with the more recent updates (I think this was for some message ordering issue, but that should be fixed now).
Gladly will revert this is you think there is a special case for having that OnDespawnObject here.
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 tried understand this but not sure why we had it. It does a recursive call into OnDespawnObject again for some reason I can't find a reason why we would want to do that. So from what I know this is not needed?
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.
Looks all good and great XML docs!
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.
The additional fix to the SendSpawnCallForObject
looks good.
This updates the object pooling example to reflect the changes from PR-977: Unity-Technologies/com.unity.netcode.gameobjects#977
* refactor and updates This updates the object pooling example to reflect the changes from PR-977: Unity-Technologies/com.unity.netcode.gameobjects#977 * additional notes This adds additional information about using more than one prefab with an override. This also adds a link to the to-be-existing folder in the master branch. * refactor Removed some code from advanced example that was not being used. * refactor Updating to most recent changes from PR-955 (yet to be merged) * refactor making changes to reflect the final version that was merged into the develop branch. Co-authored-by: Briancoughlin <76997526+Briancoughlin@users.noreply.github.com>
* refactor and updates This updates the object pooling example to reflect the changes from PR-977: Unity-Technologies/com.unity.netcode.gameobjects#977 * additional notes This adds additional information about using more than one prefab with an override. This also adds a link to the to-be-existing folder in the master branch. * refactor Removed some code from advanced example that was not being used. * refactor Updating to most recent changes from PR-955 (yet to be merged) * MTTDOC-317 initial page creation * #MTTDOC-317 update to main page * refactor making changes to reflect the final version that was merged into the develop branch. * MTTDOC-317 updating to ensure successful build * MTTDOC-317 fixing some typos and naming * update Ran through this one more time removing any references to MLAPI. I also tried to improve upon the text copy flow (might need a second pair of eyes) * update minor language tweak and italicized the reference to object pooling link * update left out the trailing * * Update object-pooling.md * Update object-pooling.md * Update object-pooling.md * Delete networktime-ticks.md Co-authored-by: Brian Coughlin <brian.coughlin@unity3d.com> Co-authored-by: Briancoughlin <76997526+Briancoughlin@users.noreply.github.com>
This updates the object pooling example to reflect the changes from PR-977: Unity-Technologies/com.unity.netcode.gameobjects#977
* refactor and updates This updates the object pooling example to reflect the changes from PR-977: Unity-Technologies/com.unity.netcode.gameobjects#977 * additional notes This adds additional information about using more than one prefab with an override. This also adds a link to the to-be-existing folder in the master branch. * refactor Removed some code from advanced example that was not being used. * refactor Updating to most recent changes from PR-955 (yet to be merged) * refactor making changes to reflect the final version that was merged into the develop branch. Co-authored-by: Briancoughlin <76997526+Briancoughlin@users.noreply.github.com>
* refactor and updates This updates the object pooling example to reflect the changes from PR-977: Unity-Technologies/com.unity.netcode.gameobjects#977 * additional notes This adds additional information about using more than one prefab with an override. This also adds a link to the to-be-existing folder in the master branch. * refactor Removed some code from advanced example that was not being used. * refactor Updating to most recent changes from PR-955 (yet to be merged) * MTTDOC-317 initial page creation * #MTTDOC-317 update to main page * refactor making changes to reflect the final version that was merged into the develop branch. * MTTDOC-317 updating to ensure successful build * MTTDOC-317 fixing some typos and naming * update Ran through this one more time removing any references to MLAPI. I also tried to improve upon the text copy flow (might need a second pair of eyes) * update minor language tweak and italicized the reference to object pooling link * update left out the trailing * * Update object-pooling.md * Update object-pooling.md * Update object-pooling.md * Delete networktime-ticks.md Co-authored-by: Brian Coughlin <brian.coughlin@unity3d.com> Co-authored-by: Briancoughlin <76997526+Briancoughlin@users.noreply.github.com>
MTT-961