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
feat: Add ability to send instantiation data to a prefab handler (#3497)
<!-- Replace this block with what this PR does and why. Describe what
you'd like reviewers to know, how you applied the engineering
principles, and any interesting tradeoffs made. Delete bullet points
below that don't apply, and update the changelog section as appropriate.
-->
<!-- Add short version of the JIRA ticket to the PR title (e.g. "feat:
new shiny feature [MTT-123]") -->
Continues the work from @Extrys in #3430.
## Changelog
- Added: A PrefabHandler that gives the ability to send data along with
object instantiation.
- Changed: Moved `INetworkPrefabInstanceHandler` to its own file.
## Testing and Documentation
- Includes unit tests.
<!-- Uncomment and mark items off with a * if this PR deprecates any
API:
### Deprecated API
- [ ] An `[Obsolete]` attribute was added along with a `(RemovedAfter
yyyy-mm-dd)` entry.
- [ ] An [api updater] was added.
- [ ] Deprecation of the API is explained in the CHANGELOG.
- [ ] The users can understand why this API was removed and what they
should use instead.
-->
## Backport
<!-- If this is a backport:
- Add the following to the PR title: "\[Backport\] ..." .
- Link to the original PR.
If this needs a backport - state this here
If a backport is not needed please provide the reason why.
If the "Backports" section is not present it will lead to a CI test
failure.
-->
This is a new feature so no backport is needed
---------
Co-authored-by: Extrys <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
39
39
40
40
- Added `SinglePlayerTransport` that provides the ability to start as a host for a single player network session. (#3473)
41
41
- When using UnityTransport >=2.4 and Unity >= 6000.1.0a1, SetConnectionData will accept a fully qualified hostname instead of an IP as a connect address on the client side. (#3441)
42
+
- Added `NetworkPrefabInstanceHandlerWithData<T>`, a variant of `INetworkPrefabInstanceHandler` that provides access to custom instantiation data directly within the `Instantiate()` method. (#3430)
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
+85-49Lines changed: 85 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,12 @@ public uint PrefabIdHash
58
58
}
59
59
}
60
60
61
+
/// <summary>
62
+
/// InstantiationData sent during the instantiation process.
63
+
/// Available to read as T parameter to <see cref="NetworkPrefabInstanceHandlerWithData{T}.Instantiate(ulong, Vector3, Quaternion, T)"/> for custom handling by user code.
64
+
/// </summary>
65
+
internalbyte[]InstantiationData;
66
+
61
67
/// <summary>
62
68
/// All <see cref="NetworkTransform"/> component instances associated with a <see cref="NetworkObject"/> component instance.
63
69
/// </summary>
@@ -2857,6 +2863,12 @@ public bool SpawnWithObservers
2857
2863
set=>ByteUtility.SetBit(refm_BitField,10,value);
2858
2864
}
2859
2865
2866
+
publicboolHasInstantiationData
2867
+
{
2868
+
get=>ByteUtility.GetBit(m_BitField,11);
2869
+
set=>ByteUtility.SetBit(refm_BitField,11,value);
2870
+
}
2871
+
2860
2872
// When handling the initial synchronization of NetworkObjects,
2861
2873
// this will be populated with the known observers.
2862
2874
publiculong[]Observers;
@@ -2884,6 +2896,7 @@ public struct TransformData : INetworkSerializeByMemcpy
2884
2896
2885
2897
publicintNetworkSceneHandle;
2886
2898
2899
+
internalintSynchronizationDataSize;
2887
2900
2888
2901
publicvoidSerialize(FastBufferWriterwriter)
2889
2902
{
@@ -2945,9 +2958,29 @@ public void Serialize(FastBufferWriter writer)
/// Interface for customizing, overriding, spawning, and destroying Network Prefabs
8
+
/// Used by <see cref="NetworkPrefabHandler"/>
9
+
/// </summary>
10
+
publicinterfaceINetworkPrefabInstanceHandler
11
+
{
12
+
/// <summary>
13
+
/// Client Side Only
14
+
/// Once an implementation is registered with the <see cref="NetworkPrefabHandler"/>, this method will be called every time
15
+
/// a Network Prefab associated <see cref="NetworkObject"/> is spawned on clients
16
+
///
17
+
/// Note On Hosts: Use the <see cref="NetworkPrefabHandler.RegisterHostGlobalObjectIdHashValues(GameObject, List{T})"/>
18
+
/// method to register all targeted NetworkPrefab overrides manually since the host will be acting as both a server and client.
19
+
///
20
+
/// Note on Pooling: If you are using a NetworkObject pool, don't forget to make the NetworkObject active
21
+
/// via the <see cref="GameObject.SetActive(bool)"/> method.
22
+
/// </summary>
23
+
/// <remarks>
24
+
/// If you need to pass custom data at instantiation time (e.g., selecting a variant, setting initialization parameters, or choosing a pre-instantiated object),
0 commit comments