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
Copy file name to clipboardExpand all lines: doc/docs/guides/game-objects/scene-objects.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,3 +22,48 @@ Networked scene objects are spawned by the ClientObjectManager and ServerObjectM
22
22
If a Scene game object is destroyed on the server before a client joins the game, then it is never spawned on new clients. It will be left in the state it is when you were editing the scene.
23
23
24
24
After a client has connected and you have called [AddCharacter](/docs/reference/Mirage/ServerObjectManager#addcharacterinetworkplayer-networkidentity) or [SpawnVisibleObjects](/docs/reference/Mirage/ServerObjectManager#spawnvisibleobjectsinetworkplayer-boolean), the client is sent a spawn message for each of the Scene objects that exist on the server, that are visible to that client. This message causes the game object on the client to be enabled and has the latest state of that game object from the server in it. This means that only game objects that are visible to the client and not destroyed on the server, are spawned on the client. Like regular non-Scene objects, these Scene objects are started with the latest state when the client joins the game.
25
+
26
+
27
+
### Filtering Scene Objects
28
+
29
+
By default, calling `SpawnSceneObjects` or `PrepareToSpawnSceneObjects` will cause Mirage to find all `NetworkIdentity` components in all loaded scenes using `Resources.FindObjectsOfTypeAll<NetworkIdentity>()`.
30
+
31
+
In some cases, like when running multiple server or client instances in the same unity process, this can be problematic as it might find objects from scenes that don't belong to the current instance.
32
+
33
+
To solve this, you can provide a custom filter by setting the `SceneObjectFilter` property on the `ServerObjectManager` and `ClientObjectManager`. This allows you to control exactly which `NetworkIdentity` components are included. If the filter is left `null`, the default behavior is used.
34
+
35
+
**Example: Only include objects from a specific scene**
36
+
```csharp
37
+
usingMirage;
38
+
usingUnityEngine;
39
+
usingUnityEngine.SceneManagement;
40
+
41
+
publicclassMySceneManager : MonoBehaviour
42
+
{
43
+
publicServerObjectManagerserverObjectManager;
44
+
publicClientObjectManagerclientObjectManager;
45
+
publicScenemyScene;
46
+
47
+
// Set the scene to use for filtering
48
+
publicvoidSetScene(Scenescene)
49
+
{
50
+
myScene=scene;
51
+
}
52
+
53
+
voidAwake()
54
+
{
55
+
// Set the filter before spawning scene objects
56
+
varfilter= (NetworkIdentityidentity) =>
57
+
{
58
+
returnidentity.gameObject.scene==myScene;
59
+
};
60
+
61
+
serverObjectManager.SceneObjectFilter=filter;
62
+
clientObjectManager.SceneObjectFilter=filter;
63
+
64
+
// Now when SpawnSceneObjects is called, it will only
0 commit comments