Skip to content

Commit a364c99

Browse files
committed
Add missing code doc
1 parent 050e150 commit a364c99

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkPrefabHandler.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,43 @@ public bool AddHandler(uint globalObjectIdHash, INetworkPrefabInstanceHandler in
7474
return false;
7575
}
7676

77+
78+
/// <inheritdoc cref="SetInstantiationData{T}(NetworkObject, T)"/>
79+
/// <param name="gameObject">
80+
/// The <see cref="GameObject"/> containing a <see cref="NetworkObject"/> to which the instantiation data will be assigned. The <see cref="NetworkObject.GlobalObjectIdHash"/> must match a handler that was previously registered.
81+
/// </param>
82+
/// <param name="instantiationData">The custom instantiation data to serialize and assign.</param>
7783
public void SetInstantiationData<T>(GameObject gameObject, T instantiationData) where T : struct, INetworkSerializable
7884
{
7985
if (gameObject.TryGetComponent<NetworkObject>(out var networkObject))
8086
{
8187
SetInstantiationData(networkObject, instantiationData);
8288
}
8389
}
84-
public void SetInstantiationData<T>(NetworkObject networkObject, T data) where T : struct, INetworkSerializable
90+
91+
/// <summary>
92+
/// Serializes and assigns custom instantiation data to a <see cref="NetworkObject"/> for use during network spawning.
93+
/// The <see cref="NetworkObject"/> must have a registered prefab handler that implements <see cref="NetworkPrefabInstanceHandlerWithData{T}"/>.
94+
/// </summary>
95+
/// <typeparam name="T"> The type of instantiation data, which must be a struct implementing <see cref="INetworkSerializable"/>.</typeparam>
96+
/// <param name="networkObject">
97+
/// The <see cref="NetworkObject"/> to which the instantiation data will be assigned. The <see cref="NetworkObject.GlobalObjectIdHash"/> must match a handler that was previously registered.
98+
/// </param>
99+
/// <param name="instantiationData">The custom instantiation data to serialize and assign.</param>
100+
public void SetInstantiationData<T>(NetworkObject networkObject, T instantiationData) where T : struct, INetworkSerializable
85101
{
86102
if (!TryGetHandlerWithData(networkObject.GlobalObjectIdHash, out var prefabHandler) || !prefabHandler.HandlesDataType<T>())
87103
{
88104
Debug.LogError("[InstantiationData] Cannot inject data: no compatible handler found for the specified data type.");
105+
return;
89106
}
90107

91108
using var writer = new FastBufferWriter(4, Collections.Allocator.Temp, int.MaxValue);
92109
var serializer = new BufferSerializer<BufferSerializerWriter>(new BufferSerializerWriter(writer));
93110

94111
try
95112
{
96-
data.NetworkSerialize(serializer);
113+
instantiationData.NetworkSerialize(serializer);
97114
networkObject.InstantiationData = writer.ToArray();
98115
}
99116
catch (Exception ex)
@@ -276,7 +293,7 @@ internal NetworkObject HandleNetworkPrefabSpawn(uint networkPrefabAssetHash, ulo
276293
{
277294
if (NetworkManager.Singleton.LogLevel <= LogLevel.Developer)
278295
{
279-
Debug.LogWarning($"[InstantiationData] Failed instantiate with data: no compatible handler found for object hash {networkPrefabAssetHash}. Instantiation data will be dropped.");
296+
Debug.LogWarning($"[InstantiationData] Failed instantiate with data: no compatible data handler found for object hash {networkPrefabAssetHash}. Instantiation data will be dropped.");
280297
}
281298
}
282299
}

0 commit comments

Comments
 (0)