Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- `netcode.gameobjects get_object` returns each NetworkBehaviour's `NetworkVariable` and `NetworkList` values as the peer sees them, and the child path of nested behaviours. `--behaviour` limits the values to one behaviour type, and `--variables false` gives the previous short form. (#4258)
- `netcode.gameobjects audit` checks in-scene NetworkObjects for a missing network id (`GlobalObjectIdHash` 0), and takes `--scope scenes` to run only that check. (#4258)
- ILPP diagnostic errors should now be clickable in the editor to go to the source of the issue. (#4250)

### Changed
Expand All @@ -22,6 +24,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Issue where a `NetworkObject` added to a scene before the scene was first saved, for example by an editor script, was saved with a `GlobalObjectIdHash` of 0 and never spawned. Saving the scene now assigns the missing id and saves it again. (#4258)
- Issue where every `NetworkObject` that started before a session logged a "Did not register because there is no session in progress!" warning when `NetworkManager.LogLevel` was `Developer`. Only `GhostObject` instances log it now. (#4245)
- Fixed a NullReferenceException that would be thrown if a MonoBehaviour derived from NetworkManager defines it's own Awake or OnEnable. (#4244)
- Issue where the unified bootstrap created a second world that ran a duplicate of every default system next to the default world. (#4243)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ To test with several players, use [Multiplayer Play Mode](https://docs.unity3d.c
| `status` | Each NetworkManager: role (host, server, client), connection state, local client id, topology, session owner, client and object counts, ticks, transport address, and whether the session runs hybrid prefabs. |
| `list_clients` | Connected clients with their player object, owned object count and round trip time. |
| `list_objects` | Spawned NetworkObjects as this peer sees them, filtered by name or owner. |
| `get_object` | One NetworkObject: owner, authority, ownership flags and who can change them, observers and NetworkBehaviours. |
| `get_object` | One NetworkObject: owner, authority, ownership flags and who can change them, observers, NetworkBehaviours (nested ones with their child path), and each behaviour's `NetworkVariable` and `NetworkList` values as this peer sees them. `--behaviour` limits the values to one behaviour type; `--variables false` leaves them out. |
| `spawn` | Instantiate and spawn a registered network prefab at a position, optionally for an owner or as a player object. |
| `despawn` | Despawn a NetworkObject, optionally keeping the GameObject. |
| `change_owner` | Give a NetworkObject to another client, following the topology's ownership rules. |
| `create_network_manager` | Add a NetworkManager with a UnityTransport to the active scene. |
| `list_prefabs` | Network prefabs lists with their prefabs, and the lists and player prefab each NetworkManager uses. |
| `register_prefab` | Add a network prefab to a network prefabs list and save the list. |
| `make_prefab` | Add a NetworkObject to a prefab's root and report its prefab id hash. |
| `audit` | Find setup problems that otherwise show when a session starts: in NetworkManagers (transport, topology, prefab lists, player prefab, hybrid prefab requirements) and in network prefabs (NetworkBehaviours without a NetworkObject, nested NetworkObjects, duplicate prefab ids, unregistered prefabs). `--scope config` or `--scope prefabs` runs one half. |
| `audit` | Find setup problems that otherwise show when a session starts: in NetworkManagers (transport, topology, prefab lists, player prefab, hybrid prefab requirements), in in-scene NetworkObjects (no network id, so they never spawn), and in network prefabs (NetworkBehaviours without a NetworkObject, nested NetworkObjects, duplicate prefab ids, unregistered prefabs). `--scope config`, `--scope scenes` or `--scope prefabs` runs one part. |

### netcode.gameobjects.profiler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ private static object ListObjects(
[CliArg("manager", "NetworkManager name or hierarchy path, when there are several.")] string manager = null)
=> NgoCliOutput.ToWire(NgoCliQueries.ListObjects(manager, nameContains, owner, limit));

[CliGroupCommand(k_Group, "One spawned NetworkObject: owner, authority, ownership flags and who may change them, observers, NetworkBehaviours, scene and position. Requires a running session.", Tags = new[] { Tag })]
[CliGroupCommand(k_Group, "One spawned NetworkObject: owner, authority, ownership flags and who may change them, observers, NetworkBehaviours (nested ones with their child path), scene, position, and each behaviour's NetworkVariable and NetworkList values as this peer sees them. Requires a running session.", Tags = new[] { Tag })]
private static object GetObject(
[CliArg("id", "NetworkObjectId, from netcode.gameobjects list_objects.", Required = true)] long id,
[CliArg("manager", "NetworkManager name or hierarchy path, when there are several.")] string manager = null)
=> NgoCliOutput.ToWire(NgoCliQueries.GetObject(id, manager));
[CliArg("manager", "NetworkManager name or hierarchy path, when there are several.")] string manager = null,
[CliArg("behaviour", "Only this NetworkBehaviour's variables, by type name.")] string behaviour = null,
[CliArg("variables", "Include NetworkVariable values. False gives the short form.")] bool variables = true)
=> NgoCliOutput.ToWire(NgoCliQueries.GetObject(id, manager, behaviour, variables));

[CliGroupCommand(k_Group, "Instantiate and spawn a registered network prefab. Server or host in client-server; any client in distributed authority (which then owns it). Returns the spawned object.", Tags = new[] { Tag })]
private static object Spawn(
Expand Down Expand Up @@ -89,9 +91,9 @@ private static object MakePrefab(
[CliArg("dry-run", "Validate and report without changing the prefab.")] bool dryRun = false)
=> NgoCliOutput.ToWire(NgoCliQueries.MakePrefab(prefab, dryRun));

[CliGroupCommand(k_Group, "Check the project for problems that otherwise show when a session starts: NetworkManager setups in the open scenes (transport, topology, prefab lists, player prefab, hierarchy, hybrid prefab requirements) and network prefabs (NetworkBehaviours without a NetworkObject, nested or misplaced NetworkObjects, NetworkManagers in network prefabs, missing or duplicate prefab ids, unregistered prefabs, broken list entries).", Tags = new[] { Tag })]
[CliGroupCommand(k_Group, "Check the project for problems that otherwise show when a session starts: NetworkManager setups in the open scenes (transport, topology, prefab lists, player prefab, hierarchy, hybrid prefab requirements), in-scene NetworkObjects without a network id, and network prefabs (NetworkBehaviours without a NetworkObject, nested or misplaced NetworkObjects, NetworkManagers in network prefabs, missing or duplicate prefab ids, unregistered prefabs, broken list entries).", Tags = new[] { Tag })]
private static object Audit(
[CliArg("scope", "all, config (NetworkManagers) or prefabs.")] string scope = "all",
[CliArg("scope", "all, config (NetworkManagers), scenes (in-scene NetworkObjects) or prefabs.")] string scope = "all",
[CliArg("folder", "Prefabs only: prefabs under this folder, e.g. Assets/Prefabs.")] string folder = null,
[CliArg("limit", "Maximum issues returned (counts include all).")] int limit = 200,
[CliArg("manager", "Config only: this NetworkManager (name or hierarchy path). Omit for all.")] string manager = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ internal class ObjectDetail : ObjectSummary
public OwnershipInfo Ownership;
public List<long> Observers;
public List<string> Behaviours = new List<string>();
/// <summary>Each behaviour's NetworkVariable values as this peer sees them; null when variables weren't asked for.</summary>
public List<BehaviourState> State;
}

internal class BehaviourState
{
public string Behaviour;
/// <summary>The behaviour's GameObject below the NetworkObject; null on the NetworkObject's own GameObject.</summary>
public string Path;
public List<VariableState> Variables = new List<VariableState>();
}

internal class VariableState
{
public string Name;
public string Type;
public object Value;
/// <summary>For a list or other collection: the full element count, though at most MaxElementsShown are shown.</summary>
public int? Count;
public bool Truncated;
public NetworkVariableReadPermission ReadPerm;
public NetworkVariableWritePermission WritePerm;
/// <summary>Why there's no value: not sent to this client, or the read failed.</summary>
public string Note;
}

internal class OwnershipInfo
Expand Down Expand Up @@ -246,6 +270,8 @@ internal class ProjectAuditResult
public int? ManagersChecked;
/// <summary>Set when network prefabs were checked.</summary>
public int? PrefabsScanned;
/// <summary>Set when the NetworkObjects in the open scenes were checked.</summary>
public int? SceneObjectsChecked;
public int Errors;
public int Warnings;
public bool Truncated;
Expand All @@ -257,7 +283,7 @@ internal class AuditIssue
/// <summary>error or warning.</summary>
public string Severity;
public string Code;
/// <summary>config (NetworkManagers) or prefabs.</summary>
/// <summary>config (NetworkManagers), scenes (in-scene NetworkObjects) or prefabs.</summary>
public string Area;
public string Asset;
public string Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ internal static MakePrefabResult MakePrefab(string prefab, bool dryRun)
internal static ProjectAuditResult Audit(string scope, string folder, int limit, string managerFilter)
{
var normalized = string.IsNullOrWhiteSpace(scope) ? "all" : scope.Trim().ToLowerInvariant();
if (normalized is not ("all" or "config" or "prefabs"))
if (normalized is not ("all" or "config" or "scenes" or "prefabs"))
{
throw new ArgumentException("scope must be all, config or prefabs.");
throw new ArgumentException("scope must be all, config, scenes or prefabs.");
}
if (limit < 1)
{
Expand All @@ -419,7 +419,7 @@ internal static ProjectAuditResult Audit(string scope, string folder, int limit,

var result = new ProjectAuditResult();
var issues = new List<AuditIssue>();
if (normalized != "prefabs")
if (normalized is "all" or "config")
{
// A project check shouldn't fail because the scene with the NetworkManager isn't open.
if (normalized == "all" && string.IsNullOrWhiteSpace(managerFilter) && FindManagers().Count == 0)
Expand All @@ -441,7 +441,24 @@ internal static ProjectAuditResult Audit(string scope, string folder, int limit,
}
}
}
if (normalized != "config")
if (normalized is "all" or "scenes")
{
var scenes = AuditScenes();
result.SceneObjectsChecked = scenes.ObjectsChecked;
foreach (var issue in scenes.Issues)
{
if (issue.Severity == "error")
{
result.Errors++;
}
else
{
result.Warnings++;
}
issues.Add(issue);
}
}
if (normalized is "all" or "prefabs")
{
var prefabs = AuditPrefabs(folder, limit);
result.PrefabsScanned = prefabs.PrefabsScanned;
Expand All @@ -462,6 +479,58 @@ internal static ProjectAuditResult Audit(string scope, string folder, int limit,
return result;
}

/// <summary>
/// Checks the NetworkObjects placed in the open scenes for a missing network id (GlobalObjectIdHash 0). NGO
/// can't match such an object across peers, so it never spawns and a session that waits for it never starts.
/// It happens when a NetworkObject is added to a scene before the scene is first saved.
/// </summary>
internal static (int ObjectsChecked, List<AuditIssue> Issues) AuditScenes()
{
var issues = new List<AuditIssue>();
var checkedCount = 0;
for (var i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
if (!scene.isLoaded)
{
continue;
}
var unsaved = string.IsNullOrEmpty(scene.path);
var missing = new List<string>();
foreach (var networkObject in FindObjects.FromSceneByType<NetworkObject>(scene, true))
{
checkedCount++;
if (networkObject.GlobalObjectIdHash == 0)
{
missing.Add(GetHierarchyPath(networkObject.transform));
}
}
if (missing.Count == 0)
{
continue;
}
var names = string.Join(", ", missing.Count > 10 ? missing.GetRange(0, 10) : missing) + (missing.Count > 10 ? $" and {missing.Count - 10} more" : "");
issues.Add(unsaved
? new AuditIssue
{
Severity = "warning",
Code = "SCENE_NOT_SAVED",
Area = "scenes",
Asset = SceneLabel(scene),
Message = $"{missing.Count} NetworkObject(s) in a scene that has never been saved have no network id yet: {names}. Save the scene; NGO assigns the ids when it has a path.",
}
: new AuditIssue
{
Severity = "error",
Code = "IN_SCENE_ID_MISSING",
Area = "scenes",
Asset = scene.path,
Message = $"{missing.Count} in-scene NetworkObject(s) have no network id (GlobalObjectIdHash 0), so they never spawn: {names}. Save the scene to assign them (a scene saved by this NGO version gets them on save), or reopen it, mark it dirty and save.",
});
}
return (checkedCount, issues);
}

/// <summary>
/// Checks network prefabs for setup problems the editor otherwise reports one at a time, in the inspector or
/// when a session starts: behaviours without a NetworkObject, nested or misplaced NetworkObjects,
Expand Down
Loading
Loading