Skip to content

Commit 0064b64

Browse files
style
Removing white spaces at the end of a line. Fixed some spelling and text related issues.
1 parent 064b3c2 commit 0064b64

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

com.unity.netcode.gameobjects/Documentation~/advanced-topics/network-prefab-handler.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Note that the `Initialize` method is only called on non-authority clients. To cu
7878

7979
When using a handler derived from `NetworkPrefabInstanceHandlerWithData`, you must manually set the instantiation data after instantiating the instance but before spawning. To do this, invoke the `NetworkPrefabInstanceHandlerWithData.SetInstantiationData` method before invoking the `NetworkObject.Spawn` method. If `SetInstantiationData` is not called, the `default` implementation will be sent to the `Instantiate` call.
8080

81-
#### Simple Example
81+
#### Simple Example
8282

8383
Below we can find a simple "pseudo" example script where the `InstantiateData` structure implements the `INetworkSerializable` interface and it will be used to serialize the instantiation data for the network prefab defined within the below `SpawnPrefabWithColor` NetworkBehaviour.
8484

@@ -103,7 +103,7 @@ public struct InstantiateData : INetworkSerializable
103103
}
104104
```
105105

106-
The below `SpawnPrefabWithColor` is an example of a NetworkBehavior component, to be placed on an in-scene placed NetworkObject, that handles the instantiation of a prefab handler (`SpawnWithColorHandler`) and the means to configure the network prefab to register with the handler. It also has a `SpawnWithColorSystem.SpawnObject` method that can be used to instantiate an instance of the assigned network prefab instance that will also have instantiation data associated with it that contains the color to be applied to the instance's `MeshRenderer`s.
106+
The below `SpawnPrefabWithColor` is an example of a NetworkBehavior component, to be placed on an in-scene placed NetworkObject, that handles the instantiation of a prefab handler (`SpawnWithColorHandler`) and the means to configure the network prefab to register with the handler. It also has a `SpawnWithColorSystem.SpawnObject` method that can be used to instantiate an instance of the assigned network prefab instance that will also have instantiation data associated with it that contains the color to be applied to the instance's `MeshRenderer`s.
107107

108108
_While there are much easier ways to synchronize the color of MeshRenderer instances across clients, this is only for example purposes._
109109

@@ -179,10 +179,10 @@ public class SpawnWithColorHandler : NetworkPrefabInstanceHandlerWithData<Instan
179179
/// instantiate the prefab, set the instantiation data, and then spawn.
180180
/// </summary>
181181
public NetworkObject InstantiateSetDataAndSpawn(Vector3 position, Quaternion rotation, InstantiateData instantiateData)
182-
{
182+
{
183183
var instance = GetPrefabInstance(position, rotation, instantiateData);
184184

185-
// Set the spawndata before spawning
185+
// Set the instantiate data before spawning
186186
m_NetworkManager.PrefabHandler.SetInstantiationData(instance, instantiateData);
187187

188188
instance.GetComponent<NetworkObject>().Spawn();
@@ -199,10 +199,9 @@ public class SpawnWithColorHandler : NetworkPrefabInstanceHandlerWithData<Instan
199199
var meshRenderers = instance.GetComponentsInChildren<MeshRenderer>();
200200
foreach (var renderer in meshRenderers)
201201
{
202-
// Assign the color to each MeshRenderer (just a psuedo example)
202+
// Assign the color to each MeshRenderer (just a pseudo example)
203203
renderer.material.color = instantiateData.Color;
204204
}
205-
206205
return instance.GetComponent<NetworkObject>();
207206
}
208207

@@ -222,7 +221,6 @@ public class SpawnWithColorHandler : NetworkPrefabInstanceHandlerWithData<Instan
222221
```
223222
When instantiating from user script for a host, server, or distributed authority client, the above `InstantiateSetDataAndSpawn` method is used. When instantiating on non-authority instances the `GetPrefabInstance` is used since the authority provides the instantiation data.
224223

225-
226224
While setting the color of a `MeshRenderer` doesn't really provide a broad spectrum use case scenario for `NetworkPrefabInstanceHandlerWithData`, the above example does provide you with a simple implementation in order to better understand:
227225

228226
- Creating a serializable structure to be serialized with the spawned network prefab.

0 commit comments

Comments
 (0)