You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* update
adding pre and post spawn methods.
clearing the m_ChildNetworkBehaviours on Awake.
* update
adding change log entries
* update
Needed to add a NetworkManager ref into the pre spawn method.
Needed to account for locally spawning.
* test
Adding test that validates the pre spawn and post spawn methods are invoked and that order of operations for OnNetworkSpawn invocation is not an issue with OnNetworkPostSpawn invocation.
* style
updating comments
* style
updating comments a bit more
* test
Migrating OnDynamicNetworkPreAndPostSpawn into its own class to avoid interfering with the generic tests.
* style
removing property no longer used and remove LF/CR
* update and test
Added NetworkBehaviour.OnNetworkSessionSynchronized and NetworkBehaviour.OnInSceneObjectsSpawned methods.
Added test to validate the above methods.
Added assets for the test to validate the above methods.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+15
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
7
7
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
8
8
9
+
## [Unreleased]
10
+
11
+
### Added
12
+
13
+
- Added `NetworkBehaviour.OnNetworkPreSpawn` and `NetworkBehaviour.OnNetworkPostSpawn` methods that provide the ability to handle pre and post spawning actions during the `NetworkObject` spawn sequence. (#2906)
14
+
- Added a client-side only `NetworkBehaviour.OnNetworkSessionSynchronized` convenience method that is invoked on all `NetworkBehaviour`s after a newly joined client has finished synchronizing with the network session in progress. (#2906)
15
+
- Added `NetworkBehaviour.OnInSceneObjectsSpawned` convenience method that is invoked when all in-scene `NetworkObject`s have been spawned after a scene has been loaded or upon a host or server starting. (#2906)
16
+
17
+
### Fixed
18
+
19
+
- Fixed issue where a `NetworkObject` component's associated `NetworkBehaviour` components would not be detected if scene loading is disabled in the editor and the currently loaded scene has in-scene placed `NetworkObject`s. (#2906)
/// Gets called after the <see cref="NetworkObject"/> is spawned. No NetworkBehaviours associated with the NetworkObject will have had <see cref="OnNetworkSpawn"/> invoked yet.
620
+
/// A reference to <see cref="NetworkManager"/> is passed in as a parameter to determine the context of execution (IsServer/IsClient)
621
+
/// </summary>
622
+
/// <remarks>
623
+
/// <param name="networkManager">a ref to the <see cref="NetworkManager"/> since this is not yet set on the <see cref="NetworkBehaviour"/></param>
624
+
/// The <see cref="NetworkBehaviour"/> will not have anything assigned to it at this point in time.
625
+
/// Settings like ownership, NetworkBehaviourId, NetworkManager, and most other spawn related properties will not be set.
626
+
/// This can be used to handle things like initializing/instantiating a NetworkVariable or the like.
/// Gets called when the <see cref="NetworkObject"/> gets spawned, message handlers are ready to be registered and the network is setup.
620
632
/// </summary>
621
633
publicvirtualvoidOnNetworkSpawn(){}
622
634
635
+
/// <summary>
636
+
/// Gets called after the <see cref="NetworkObject"/> is spawned. All NetworkBehaviours associated with the NetworkObject will have had <see cref="OnNetworkSpawn"/> invoked.
637
+
/// </summary>
638
+
/// <remarks>
639
+
/// Will be invoked on each <see cref="NetworkBehaviour"/> associated with the <see cref="NetworkObject"/> being spawned.
640
+
/// All associated <see cref="NetworkBehaviour"/> components will have had <see cref="OnNetworkSpawn"/> invoked on the spawned <see cref="NetworkObject"/>.
641
+
/// </remarks>
642
+
protectedvirtualvoidOnNetworkPostSpawn(){}
643
+
644
+
/// <summary>
645
+
/// [Client-Side Only]
646
+
/// When a new client joins it is synchronized with all spawned NetworkObjects and scenes loaded for the session joined. At the end of the synchronization process, when all
647
+
/// <see cref="NetworkObject"/>s and scenes (if scene management is enabled) have finished synchronizing, all NetworkBehaviour components associated with spawned <see cref="NetworkObject"/>s
648
+
/// will have this method invoked.
649
+
/// </summary>
650
+
/// <remarks>
651
+
/// This can be used to handle post synchronization actions where you might need to access a different NetworkObject and/or NetworkBehaviour not local to the current NetworkObject context.
652
+
/// This is only invoked on clients during a client-server network topology session.
/// When a scene is loaded an in-scene placed NetworkObjects are all spawned, this method is invoked on all of the newly spawned in-scene placed NetworkObjects.
659
+
/// </summary>
660
+
/// <remarks>
661
+
/// This can be used to handle post scene loaded actions for in-scene placed NetworkObjcts where you might need to access a different NetworkObject and/or NetworkBehaviour not local to the current NetworkObject context.
662
+
/// </remarks>
663
+
protectedvirtualvoidOnInSceneObjectsSpawned(){}
664
+
623
665
/// <summary>
624
666
/// Gets called when the <see cref="NetworkObject"/> gets despawned. Is called both on the server and clients.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Runtime/Serialization/NetworkBehaviourReference.cs
+2-2
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ public NetworkBehaviourReference(NetworkBehaviour networkBehaviour)
45
45
/// <returns>True if the <see cref="NetworkBehaviour"/> was found; False if the <see cref="NetworkBehaviour"/> was not found. This can happen if the corresponding <see cref="NetworkObject"/> has not been spawned yet. you can try getting the reference at a later point in time.</returns>
/// <returns>True if the <see cref="NetworkBehaviour"/> was found; False if the <see cref="NetworkBehaviour"/> was not found. This can happen if the corresponding <see cref="NetworkObject"/> has not been spawned yet. you can try getting the reference at a later point in time.</returns>
Debug.LogError("Spawning NetworkObjects with nested NetworkObjects is only supported for scene objects. Child NetworkObjects will not be spawned over the network!");
0 commit comments