Skip to content

Commit 1b17d38

Browse files
authored
Merge branch 'develop-2.0.0' into docs/link-fixes
2 parents a1d5bbf + 9b620fb commit 1b17d38

31 files changed

Lines changed: 1248 additions & 856 deletions

.yamato/_triggers.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pr_code_changes_checks:
8989
# Note that our daily tests will anyway run both test configurations in "minimal supported" and "trunk" configurations
9090
- .yamato/desktop-standalone-tests.yml#desktop_standalone_test_testproject_ubuntu_il2cpp_{{ pinnedTrunk }}
9191
- .yamato/cmb-service-standalone-tests.yml#cmb_service_standalone_test_testproject_ubuntu_il2cpp_{{ pinnedTrunk }}
92-
# Run code coverage test
93-
- .yamato/code-coverage.yml#code_coverage_ubuntu_{{ validation_editors.default }}
92+
# Run code coverage test (PRs use the pinned "safe" trunk)
93+
- .yamato/code-coverage.yml#code_coverage_project_test_testproject_ubuntu_{{ pinnedTrunk }}
9494
triggers:
9595
expression: |-
9696
(pull_request.comment eq "ngo" OR
@@ -159,8 +159,8 @@ develop_nightly:
159159
- .yamato/project-updated-dependencies-test.yml#updated-dependencies_testproject_NGO_win_6000.0
160160
# Run API validation to early-detect all new APIs that would force us to release new minor version of the package. Note that for this to work the package version in package.json must correspond to "actual package state" which means that it should be higher than last released version
161161
- .yamato/vetting-test.yml#vetting_test
162-
# Run code coverage test
163-
- .yamato/code-coverage.yml#code_coverage_ubuntu_{{ validation_editors.default }}
162+
# Run code coverage test (nightly uses actual trunk)
163+
- .yamato/code-coverage.yml#code_coverage_project_test_testproject_ubuntu_trunk
164164

165165

166166
# Run all tests on weekly bases

.yamato/code-coverage.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,37 @@
22
---
33

44
# DESCRIPTION--------------------------------------------------------------------------
5-
# This job is responsible for executing package tests with code coverage analysis enabled.
5+
# This job runs the in-repo testproject tests with code coverage analysis enabled.
6+
# The project tests also exercise the NGO package tests, so a separate package-test coverage job is not needed.
67
# Coverage analysis provides insights into:
78
# Test coverage metrics for NGO assemblies
89
# Line and branch coverage statistics
910
# Generated HTML reports for coverage visualization
1011
# Additional metrics for coverage analysis
1112

1213
# CONFIGURATION STRUCTURE--------------------------------------------------------------
13-
# Jobs are generated using nested loops through:
14-
# 1. For default platform only (Ubuntu) since coverage would not vary between platforms (no need for checks on more platforms)
15-
# 2. For default editor version (trunk) since coverage would not vary between editors (no need for checks on more editors)
14+
# Jobs are generated for:
15+
# 1. Default platform only (Ubuntu) since coverage would not vary between platforms (no need for checks on more platforms)
16+
# 2. Two editors: actual "trunk" (used by nightly) and the "pinnedTrunk" safe version (used by PRs).
17+
# Occasionally trunk breaks our tests, so PRs run against a pinned "safe" trunk while nightly runs actual trunk.
1618

1719
#TECHNICAL CONSIDERATIONS---------------------------------------------------------------
18-
# In theory this job also runs package tests, but we don't want to use it as default since is heavier (because of added coverage analysis) and coverage is not changing that often
1920
# Requires Unity Editor installation
2021
# Burst compilation is disabled to ensure accurate coverage measurement
2122
# In order to properly use -coverage-results-path parameter we need to start it with $PWD (which means the absolute path). Otherwise coverage results will not be visible
2223

2324
# QUALITY CONSIDERATIONS--------------------------------------------------------------------
24-
# To see where this job is included (in trigger job definitions) look into _triggers.yml file
25-
25+
# To see where this job is included (in trigger job definitions) look into _triggers.yml file. Currently:
26+
# [Code Coverage] Project Test runs on PR changes (pr_code_changes_checks, pinnedTrunk) and nightly (develop_nightly, trunk)
2627

28+
{% assign coverage_editors = "trunk," | append: pinnedTrunk | split: "," -%}
2729

2830
{% for platform in test_platforms.default -%}
29-
{% for editor in validation_editors.default -%}
30-
code_coverage_{{ platform.name }}_{{ editor }}:
31-
name: Code Coverage - NGO [{{ platform.name }}, {{ editor }}]
31+
{% for project in projects.default -%}
32+
{% for editor in coverage_editors -%}
33+
{% if editor == "trunk" -%}{% assign editor_label = "trunk" -%}{% else -%}{% assign editor_label = "pinnedTrunk" -%}{% endif -%}
34+
code_coverage_project_test_{{ project.name }}_{{ platform.name }}_{{ editor }}:
35+
name: '[Code Coverage] Project Test - NGO {{ project.name }} [{{ platform.name }}, {{ editor }}]'
3236
agent:
3337
type: {{ platform.type }}
3438
image: {{ platform.image }}
@@ -38,13 +42,14 @@ code_coverage_{{ platform.name }}_{{ editor }}:
3842
{% endif %}
3943
commands:
4044
- unity-downloader-cli --fast --wait -u {{ editor }} -c Editor {% if platform.name == "mac" %} --arch arm64 {% endif %} # For macOS we use ARM64 models
41-
- upm-pvp create-test-project test-project --packages "upm-ci~/packages/*.tgz" --unity .Editor
42-
- UnifiedTestRunner --suite=editor --suite=playmode --editor-location=.Editor --testproject=test-project --enable-code-coverage --coverage-upload-options="reportsDir:$PWD/test-results/CoverageResults;name:NGOv2_{{ platform.name }}_{{ editor }};flags:NGOv2_{{ platform.name }}_{{ editor }};verbose" --coverage-results-path=$PWD/test-results/CoverageResults --coverage-options="generateHtmlReport;generateAdditionalMetrics;assemblyFilters:+Unity.Netcode.Editor,+Unity.Netcode.Runtime" --extra-editor-arg=--burst-disable-compilation --timeout={{ test_timeout }} --rerun-strategy=Test --retry={{ num_test_retries }} --clean-library-on-rerun --artifacts-path=test-results
45+
- UnifiedTestRunner --testproject={{ project.path }} --suite=editor --suite=playmode --editor-location=.Editor --enable-code-coverage --coverage-upload-options="reportsDir:$PWD/test-results/CoverageResults;name:NGOv2_project_{{ project.name }}_{{ platform.name }}_{{ editor_label }};flags:NGOv2_project_{{ project.name }}_{{ platform.name }}_{{ editor_label }};verbose" --coverage-results-path=$PWD/test-results/CoverageResults --coverage-options="generateHtmlReport;generateAdditionalMetrics;assemblyFilters:+Unity.Netcode.Editor,+Unity.Netcode.Runtime" --extra-editor-arg=--burst-disable-compilation --timeout={{ test_timeout }} --rerun-strategy=Test --retry={{ num_test_retries }} --clean-library-on-rerun --artifacts-path=test-results
4346
artifacts:
4447
logs:
4548
paths:
4649
- "test-results/**/*"
4750
dependencies:
51+
- .yamato/_run-all.yml#run_quick_checks # initial checks to perform fast validation of common errors
4852
- .yamato/package-pack.yml#package_pack_-_ngo_{{ platform.name }}
4953
{% endfor -%}
5054
{% endfor -%}
55+
{% endfor -%}

Tools/CI/service.cmb/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Testing against the CMB Service
22

3-
The CMB Service is a tool that is external to our repository. The tool is inside the `runtime` folder in the [mps-common-multiplayer-backend](https://github.com/Unity-Technologies/mps-common-multiplayer-backend) repository.
3+
The CMB Service is a tool that is external to our repository. The tool is inside the `runtime` folder of the [CMB service](https://github.com/Unity-Technologies/unity-player-services/tree/main/services/common-multiplayer-backend) in the Unity Player Services monorepo.
44

55
Due to this, there is some more setup needed when running tests against the CMB Service.
66

@@ -56,3 +56,7 @@ The following environment variables allow for further configuration of the setup
5656
`CMB_SERVICE_PORT` defines the port where the tests will try to connect to the service (defaults to `7789`).
5757

5858
`NGO_HOST` defines the http address where the tests will try to connect to the service (defaults to `127.0.0.1`).
59+
60+
## Running on CI (Yamato)
61+
62+
The CMB tests can also be run from Yamato. The jobs are defined in [`.yamato/cmb-service-standalone-tests.yml`](../../../.yamato/cmb-service-standalone-tests.yml) and appear in Yamato as `CMB Service Test - NGO <project> - [<platform>, <editor>, <backend>]`. The job can be triggered manually from any branch meaning it can be easier to run the CMB tests from Yamato rather than set them up locally. The test uses [`run_cmb_service.sh`](./run_cmb_service.sh) to setup and run the CMB service.

Tools/CI/service.cmb/run_cmb_service.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Example usage:
1818
# ./<path-to-script>/run_cmb_service.sh -e 7788 -s 7799
1919

20-
# This script is currently used in the desktop-standalone-tests yamato job.
20+
# This script is currently used in the cmb-service-standalone-tests yamato job (found at ../../../.yamato/cmb-service-standalone-tests.yml).
2121

2222
# TECHNICAL CONSIDERATIONS---------------------------------------------------------------
2323
# This is a bash script and so needs to be run on a Unix based system.
@@ -136,11 +136,14 @@ else
136136
logMessage "Protocol Buffer Compiler Installed & ENV variables verified!\n PROTOC path is: $PROTOC"
137137
fi
138138

139-
# clone the cmb service repo
140-
git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
139+
# Sparse-checkout only the CMB service directory from the unity-player-services monorepo.
140+
# --filter=blob:none + --depth 1 avoids downloading file contents and history for the rest of the monorepo.
141+
git clone --depth 1 --filter=blob:none --sparse https://github.com/Unity-Technologies/unity-player-services.git
142+
cd ./unity-player-services
143+
git sparse-checkout set services/common-multiplayer-backend/runtime
141144

142145
# navigate to the cmb service directory
143-
cd ./mps-common-multiplayer-backend/runtime
146+
cd ./services/common-multiplayer-backend/runtime
144147

145148
# Install rust
146149
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
1414
### Changed
1515

1616

17+
18+
1719
### Deprecated
1820

1921

@@ -22,6 +24,10 @@ Additional documentation and release notes are available at [Multiplayer Documen
2224

2325
### Fixed
2426

27+
- Issue with not being able to spawn initially disabled in-scene placed objects. (#4093)
28+
- Issue with pre-instantiated network prefab instances being marked as in-scene placed. Now pre-instantiated network prefabs are dynamically spawned. (#4093)
29+
- Issue where a user could spawn runtime created `NetworkObject` that has a GlobalObjectIdHash of zero. These are not valid instances and will no longer be allowed to spawn. (#4093)
30+
2531

2632
### Security
2733

com.unity.netcode.gameobjects/Documentation~/basics/scenemanagement/inscene-placed-networkobjects.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,13 @@ public class MyInSceneNetworkObjectBehaviour : NetworkBehaviour
184184
> [!NOTE]
185185
> You only need to enable the NetworkObject on the server-side to be able to respawn it. Netcode for GameObjects only enables a disabled in-scene placed NetworkObject on the client-side if the server-side spawns it. This **does not** apply to dynamically spawned `NetworkObjects`. Refer to [the object pooling page](../../advanced-topics/object-pooling.md) for an example of recycling dynamically spawned NetworkObjects.
186186
187+
### Pre-disabled in-scene placed NetworkObjects
188+
189+
To initialize an in-scene placed NetworkObject in a disabled state and spawn it later, set its GameObject to inactive in the Editor while the respective scene is open. Once a networked session begins, you can re-enable and spawn it at any time.
190+
187191
### Setting an in-scene placed NetworkObject to a despawned state when instantiating
188192

189-
Since in-scene placed NetworkObjects are automatically spawned when their respective scene has finished loading during a network session, you might run into the scenario where you want it to start in a despawned state until a certain condition has been met. To do this, you need to add some additional code in the `OnNetworkSpawn` part of your NetworkBehaviour component:
193+
To programmatically disable an in-scene placed NetworkObject, add some additional code in the `OnNetworkSpawn` part of a NetworkBehaviour component:
190194

191195
```csharp
192196
using UnityEngine;

com.unity.netcode.gameobjects/Documentation~/components/core/networkobject.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ When spawning a NetworkObject, the `NetworkObject.GlobalObjectIdHash` value init
1919

2020
You can use [NetworkBehaviours](networkbehaviour.md) to add your own custom Netcode logic to the associated NetworkObject.
2121

22+
### What is a valid NetworkObject?
23+
24+
There are two categories of NetworkObjects:
25+
* Dynamically instantiated
26+
* [In-scene placed](../../basics/scenemanagement/inscene-placed-networkobjects.md)
27+
28+
The following provides the validity requirements for both types.
29+
30+
#### Dynamically instantiated network prefabs
31+
32+
Dynamically instantiated network prefabs must:
33+
34+
* Be a valid [network prefab](./networkobject.md#network-prefabs) created within the Editor.
35+
* Be registered in a network prefab list that's assigned to your NetworkManager.
36+
37+
#### In-scene placed network prefabs
38+
39+
In-scene placed network prefabs must:
40+
41+
* Be a valid network prefab instance within a scene.
42+
* Be a GameObject with a NetworkObject component created within the scene while in the Editor.
43+
44+
### What is an invalid NetworkObject?
45+
46+
GameObjects that have NetworkObject components added to them during runtime are **not supported** and will result in the NetworkObject's `GlobalObjectIdHash` being zero, which causes synchronization issues. In the event you make this mistake, a warning message will be logged and the NetworkObject won't be spawned.
47+
2248
### Component order
2349

2450
The order of components on a networked GameObject matters. When adding netcode components to a GameObject, ensure that the NetworkObject component is ordered before any NetworkBehaviour components.

com.unity.netcode.gameobjects/Editor/InScenePlacedProcessor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public void OnProcessScene(Scene scene, BuildReport report)
2424
log.AddInfo(scene.name, scene.handle);
2525
foreach (var networkObject in FindObjects.FromSceneByType<NetworkObject>(scene, true))
2626
{
27+
// Trap for users just creating things during runtime where this will be zero.
28+
if (networkObject.GlobalObjectIdHash == 0)
29+
{
30+
log.Warning(new Context(LogLevel.Developer, $"{nameof(NetworkObject)}'s GlobalObjectIdHash value is zero! Runtime creating of {nameof(NetworkObject)}s is not supported. Skipping processing.").AddNetworkObject(networkObject));
31+
continue;
32+
}
2733
if (networkObject.SceneOrigin.IsValid() && networkObject.SceneOrigin.handle != scene.handle)
2834
{
2935
log.Warning(new Context(LogLevel.Developer, $"{nameof(NetworkObject)}'s SceneOrigin doesn't match current scene being processed! Skipping processing.").AddInfo("SceneOrigin", networkObject.SceneOriginHandle).AddNetworkObject(networkObject));
@@ -36,7 +42,15 @@ public void OnProcessScene(Scene scene, BuildReport report)
3642
continue;
3743
}
3844

45+
// If already marked, the do nothing.
46+
if (networkObject.InScenePlaced)
47+
{
48+
continue;
49+
}
50+
3951
networkObject.InScenePlaced = true;
52+
// Will not be true when making a build and the values are serialized.
53+
networkObject.InScenePlacedPostProcessorMarkedDuringRuntime = Application.isPlaying;
4054
}
4155
}
4256
}

com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ protected virtual void Awake()
768768
if (!m_Animator)
769769
{
770770
#if !UNITY_EDITOR
771-
Debug.LogError($"{nameof(NetworkAnimator)} {name} does not have an {nameof(UnityEngine.Animator)} assigned to it. The {nameof(NetworkAnimator)} will not initialize properly.");
771+
Debug.LogWarning($"{nameof(NetworkAnimator)} {name} does not have an {nameof(UnityEngine.Animator)} assigned to it. The {nameof(NetworkAnimator)} will not initialize properly.");
772772
#endif
773773
return;
774774
}

0 commit comments

Comments
 (0)