Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
b5eff95
fix
NoelStephensUnity Apr 22, 2022
257fe04
Update CHANGELOG.md
NoelStephensUnity Apr 22, 2022
8db7adc
Update CHANGELOG.md
NoelStephensUnity Apr 22, 2022
5be2ba2
fix
NoelStephensUnity Apr 24, 2022
89472c6
Update CHANGELOG.md
NoelStephensUnity Apr 25, 2022
fc3410e
style
NoelStephensUnity Apr 25, 2022
675cd98
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 25, 2022
7b5683a
Update CHANGELOG.md
NoelStephensUnity Apr 25, 2022
d907319
style
NoelStephensUnity Apr 25, 2022
5103767
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 25, 2022
230bc47
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 26, 2022
55fa5e0
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 26, 2022
b15b943
fix
NoelStephensUnity Apr 26, 2022
27daaa1
update
NoelStephensUnity Apr 26, 2022
6907249
fix
NoelStephensUnity Apr 26, 2022
319f5bb
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 26, 2022
5f91041
Update NetworkSceneManagerEventDataPoolTest.cs
NoelStephensUnity Apr 26, 2022
a0fd2f0
style
NoelStephensUnity Apr 26, 2022
48c9858
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 26, 2022
3c6554c
style
NoelStephensUnity Apr 26, 2022
b2df454
test - integration test clients now load scenes
NoelStephensUnity Apr 26, 2022
0b00a30
test - fix
NoelStephensUnity Apr 27, 2022
2e70ef4
test - fix
NoelStephensUnity Apr 27, 2022
b286c85
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 27, 2022
ce797b0
fix
NoelStephensUnity Apr 27, 2022
e2ef457
fix - NetworkSceneManager.GetSceneRelativeInSceneNetworkObject
NoelStephensUnity Apr 28, 2022
8834920
fix - AddDespawnedInSceneNetworkObjects
NoelStephensUnity Apr 28, 2022
506ba02
test - fix - Integration test client scene loading
NoelStephensUnity Apr 28, 2022
b539f89
test update
NoelStephensUnity Apr 28, 2022
877cfb0
test assets
NoelStephensUnity Apr 28, 2022
828167f
test fix
NoelStephensUnity Apr 28, 2022
edf92d4
test fix
NoelStephensUnity Apr 28, 2022
8dd4853
test fix
NoelStephensUnity Apr 28, 2022
2d5422e
test fix
NoelStephensUnity Apr 28, 2022
9c4f29f
test InScenePlacedNetworkObjects
NoelStephensUnity Apr 28, 2022
d21be92
fix
NoelStephensUnity Apr 28, 2022
ebd8fc3
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 28, 2022
7e8fdd9
fix
NoelStephensUnity Apr 28, 2022
21eef1f
style
NoelStephensUnity Apr 28, 2022
f9a3815
Update ObjectNameIdentifier.cs
NoelStephensUnity Apr 28, 2022
ab63346
style
NoelStephensUnity Apr 28, 2022
58861da
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 28, 2022
efd8ac3
style
NoelStephensUnity Apr 28, 2022
107a8f1
update and style
NoelStephensUnity Apr 28, 2022
7574a59
update
NoelStephensUnity Apr 28, 2022
87c3e1e
update
NoelStephensUnity Apr 28, 2022
1118787
style
NoelStephensUnity Apr 28, 2022
b873dac
fix
NoelStephensUnity Apr 28, 2022
8c36b42
fix consoles
NoelStephensUnity Apr 28, 2022
eab3752
fix
NoelStephensUnity Apr 28, 2022
9679d40
test - fix
NoelStephensUnity Apr 29, 2022
9c0adfa
update
NoelStephensUnity Apr 29, 2022
556692c
Update CHANGELOG.md
NoelStephensUnity Apr 29, 2022
befae84
update
NoelStephensUnity Apr 29, 2022
a6b1532
test update
NoelStephensUnity Apr 29, 2022
63ffa52
style
NoelStephensUnity Apr 29, 2022
81d14a4
test
NoelStephensUnity Apr 29, 2022
39b9dea
test
NoelStephensUnity Apr 29, 2022
f93cf15
test fix
NoelStephensUnity Apr 29, 2022
e87c891
test fix
NoelStephensUnity Apr 29, 2022
affd7b6
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity Apr 29, 2022
1cf822a
Test Fix
NoelStephensUnity Apr 29, 2022
6773a40
test fix
NoelStephensUnity Apr 29, 2022
09208d4
fix
NoelStephensUnity May 1, 2022
98a4803
test and style
NoelStephensUnity May 1, 2022
0dfcac8
style
NoelStephensUnity May 1, 2022
8630d2a
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity May 2, 2022
f94ec9b
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity May 5, 2022
4a8d137
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity May 6, 2022
f792373
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity May 9, 2022
a18d763
Merge branch 'develop' into fix/mtt-2924-despawned-scene-objects-dont…
NoelStephensUnity May 9, 2022
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
4 changes: 3 additions & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Changed

- `unmanaged` structs are no longer universally accepted as RPC parameters because some structs (i.e., structs with pointers in them, such as `NativeList<T>`) can't be supported by the default memcpy struct serializer. Structs that are intended to be serialized across the network must add `INetworkSerializeByMemcpy` to the interface list (i.e., `struct Foo : INetworkSerializeByMemcpy`). This interface is empty and just serves to mark the struct as compatible with memcpy serialization. For external structs you can't edit, you can pass them to RPCs by wrapping them in `ForceNetworkSerializeByMemcpy<T>`. (#1901)
- Changed requirement to register in-scene placed NetworkObjects with `NetworkManager` in order to respawn them. In-scene placed NetworkObjects are now automatically tracked during runtime and no longer need to be registered as a NetworkPrefab. (#1898)

### Removed
- Removed `SIPTransport` (#1870)

- Removed `ClientNetworkTransform` from the package samples and moved to Boss Room's Utilities package which can be found [here](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority/ClientNetworkTransform.cs).

### Fixed

- Fixed issue where `NetworkSceneManager` did not synchronize despawned in-scene placed NetworkObjects. (#1898)
Comment thread
NoelStephensUnity marked this conversation as resolved.
- Fixed `NetworkTransform` generating false positive rotation delta checks when rolling over between 0 and 360 degrees. (#1890)
- Fixed client throwing an exception if it has messages in the outbound queue when processing the `NetworkEvent.Disconnect` event and is using UTP. (#1884)
- Fixed issue during client synchronization if 'ValidateSceneBeforeLoading' returned false it would halt the client synchronization process resulting in a client that was approved but not synchronized or fully connected with the server. (#1883)
Expand All @@ -36,6 +37,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
## [1.0.0-pre.7] - 2022-04-06

### Added

- Added editor only check prior to entering into play mode if the currently open and active scene is in the build list and if not displays a dialog box asking the user if they would like to automatically add it prior to entering into play mode. (#1828)
- Added `UnityTransport` implementation and `com.unity.transport` package dependency (#1823)
- Added `NetworkVariableWritePermission` to `NetworkVariableBase` and implemented `Owner` client writable netvars. (#1762)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public override void OnInspectorGUI()
/// </summary>
private void OnEnable()
{
// This can be null and throw an exception when running test runner in the editor
if (target == null)
{
return;
}
// When we first add a NetworkBehaviour this editor will be enabled
// so we go ahead and check for an already existing NetworkObject here
CheckForNetworkObject((target as NetworkBehaviour).gameObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ internal void HandleApproval(ulong ownerClientId, bool createPlayerObject, uint?

if (createPlayerObject)
{
var networkObject = SpawnManager.CreateLocalNetworkObject(false, playerPrefabHash ?? NetworkConfig.PlayerPrefab.GetComponent<NetworkObject>().GlobalObjectIdHash, ownerClientId, null, position, rotation);
var networkObject = SpawnManager.CreateLocalNetworkObject(false, playerPrefabHash ?? NetworkConfig.PlayerPrefab.GetComponent<NetworkObject>().GlobalObjectIdHash, ownerClientId, null, null, position, rotation);
SpawnManager.SpawnNetworkObjectLocally(networkObject, SpawnManager.GetNetworkObjectId(), false, true, ownerClientId, false);

ConnectedClients[ownerClientId].PlayerObject = networkObject;
Expand Down
63 changes: 46 additions & 17 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ internal string GetNameForMetrics()
#endif
}

private readonly HashSet<ulong> m_EmptyULongHashSet = new HashSet<ulong>();
/// <summary>
/// Returns Observers enumerator
/// </summary>
Expand All @@ -159,7 +160,7 @@ public HashSet<ulong>.Enumerator GetObservers()
{
if (!IsSpawned)
{
throw new SpawnStateException("Object is not spawned");
return m_EmptyULongHashSet.GetEnumerator();
}

return Observers.GetEnumerator();
Expand All @@ -174,9 +175,8 @@ public bool IsNetworkVisibleTo(ulong clientId)
{
if (!IsSpawned)
{
throw new SpawnStateException("Object is not spawned");
return false;
}

return Observers.Contains(clientId);
}

Expand Down Expand Up @@ -372,7 +372,7 @@ private void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool play
throw new NotServerException($"Only server can spawn {nameof(NetworkObject)}s");
}

NetworkManager.SpawnManager.SpawnNetworkObjectLocally(this, NetworkManager.SpawnManager.GetNetworkObjectId(), false, playerObject, ownerClientId, destroyWithScene);
NetworkManager.SpawnManager.SpawnNetworkObjectLocally(this, NetworkManager.SpawnManager.GetNetworkObjectId(), IsSceneObject.HasValue && IsSceneObject.Value, playerObject, ownerClientId, destroyWithScene);

for (int i = 0; i < NetworkManager.ConnectedClientsList.Count; i++)
{
Expand Down Expand Up @@ -865,16 +865,17 @@ public struct TransformData : INetworkSerializeByMemcpy
public NetworkObject OwnerObject;
public ulong TargetClientId;

public int NetworkSceneHandle;
Comment thread
NoelStephensUnity marked this conversation as resolved.

public unsafe void Serialize(FastBufferWriter writer)
{
if (!writer.TryBeginWrite(
sizeof(HeaderData) +
(Header.HasParent ? FastBufferWriter.GetWriteSize(ParentObjectId) : 0) +
(Header.HasTransform ? FastBufferWriter.GetWriteSize(Transform) : 0) +
(Header.IsReparented
? FastBufferWriter.GetWriteSize(IsLatestParentSet) +
(IsLatestParentSet ? FastBufferWriter.GetWriteSize<ulong>() : 0)
: 0)))
var writeSize = sizeof(HeaderData);
writeSize += Header.HasParent ? FastBufferWriter.GetWriteSize(ParentObjectId) : 0;
writeSize += Header.HasTransform ? FastBufferWriter.GetWriteSize(Transform) : 0;
writeSize += Header.IsReparented ? FastBufferWriter.GetWriteSize(IsLatestParentSet) + (IsLatestParentSet ? FastBufferWriter.GetWriteSize<ulong>() : 0) : 0;
writeSize += Header.IsSceneObject ? FastBufferWriter.GetWriteSize<int>() : 0;

if (!writer.TryBeginWrite(writeSize))
{
throw new OverflowException("Could not serialize SceneObject: Out of buffer space.");
}
Expand All @@ -900,6 +901,16 @@ public unsafe void Serialize(FastBufferWriter writer)
}
}

// In-Scene NetworkObjects are uniquely identified NetworkPrefabs defined by their
// NetworkSceneHandle and GlobalObjectIdHash. Since each loaded scene has a unique
// handle, it provides us with a unique and persistent "scene prefab asset" instance.
// This is only set on in-scene placed NetworkObjects to reduce the over-all packet
// sizes for dynamically spawned NetworkObjects.
if (Header.IsSceneObject)
{
writer.WriteValue(OwnerObject.gameObject.scene.handle);
}

OwnerObject.WriteNetworkVariableData(writer, TargetClientId);
}

Expand All @@ -910,10 +921,12 @@ public unsafe void Deserialize(FastBufferReader reader)
throw new OverflowException("Could not deserialize SceneObject: Out of buffer space.");
}
reader.ReadValue(out Header);
if (!reader.TryBeginRead(
(Header.HasParent ? FastBufferWriter.GetWriteSize(ParentObjectId) : 0) +
(Header.HasTransform ? FastBufferWriter.GetWriteSize(Transform) : 0) +
(Header.IsReparented ? FastBufferWriter.GetWriteSize(IsLatestParentSet) : 0)))
var readSize = Header.HasParent ? FastBufferWriter.GetWriteSize(ParentObjectId) : 0;
readSize += Header.HasTransform ? FastBufferWriter.GetWriteSize(Transform) : 0;
readSize += Header.IsReparented ? FastBufferWriter.GetWriteSize(IsLatestParentSet) + (IsLatestParentSet ? FastBufferWriter.GetWriteSize<ulong>() : 0) : 0;
readSize += Header.IsSceneObject ? FastBufferWriter.GetWriteSize<int>() : 0;

if (!reader.TryBeginRead(readSize))
{
throw new OverflowException("Could not deserialize SceneObject: Out of buffer space.");
}
Expand All @@ -937,6 +950,16 @@ public unsafe void Deserialize(FastBufferReader reader)
LatestParent = latestParent;
}
}

// In-Scene NetworkObjects are uniquely identified NetworkPrefabs defined by their
// NetworkSceneHandle and GlobalObjectIdHash. Since each loaded scene has a unique
// handle, it provides us with a unique and persistent "scene prefab asset" instance.
// Client-side NetworkSceneManagers use this to locate their local instance of the
// NetworkObject instance.
if (Header.IsSceneObject)
{
reader.ReadValue(out NetworkSceneHandle);
}
}
}

Expand Down Expand Up @@ -1006,6 +1029,7 @@ internal static NetworkObject AddSceneObject(in SceneObject sceneObject, FastBuf
Vector3? position = null;
Quaternion? rotation = null;
ulong? parentNetworkId = null;
int? networkSceneHandle = null;

if (sceneObject.Header.HasTransform)
{
Expand All @@ -1018,10 +1042,15 @@ internal static NetworkObject AddSceneObject(in SceneObject sceneObject, FastBuf
parentNetworkId = sceneObject.ParentObjectId;
}

if (sceneObject.Header.IsSceneObject)
{
networkSceneHandle = sceneObject.NetworkSceneHandle;
}

//Attempt to create a local NetworkObject
var networkObject = networkManager.SpawnManager.CreateLocalNetworkObject(
sceneObject.Header.IsSceneObject, sceneObject.Header.Hash,
sceneObject.Header.OwnerClientId, parentNetworkId, position, rotation, sceneObject.Header.IsReparented);
sceneObject.Header.OwnerClientId, parentNetworkId, networkSceneHandle, position, rotation, sceneObject.Header.IsReparented);

networkObject?.SetNetworkParenting(sceneObject.Header.IsReparented, sceneObject.LatestParent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context)
}

ObjectInfo.Deserialize(reader);
if (!networkManager.NetworkConfig.ForceSamePrefabs && !networkManager.SpawnManager.HasPrefab(ObjectInfo.Header.IsSceneObject, ObjectInfo.Header.Hash))
if (!networkManager.NetworkConfig.ForceSamePrefabs && !networkManager.SpawnManager.HasPrefab(ObjectInfo))
{
networkManager.DeferredMessageManager.DeferMessage(IDeferredMessageManager.TriggerType.OnAddPrefab, ObjectInfo.Header.Hash, reader, ref context);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Unity.Netcode
internal struct DestroyObjectMessage : INetworkMessage, INetworkSerializeByMemcpy
{
public ulong NetworkObjectId;
public bool DestroyGameObject;

public void Serialize(FastBufferWriter writer)
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public void Handle(ref NetworkContext context)
}

networkManager.NetworkMetrics.TrackObjectDestroyReceived(context.SenderId, networkObject, context.MessageSize);
networkManager.SpawnManager.OnDespawnObject(networkObject, true);
networkManager.SpawnManager.OnDespawnObject(networkObject, DestroyGameObject);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ struct SceneEventAction
{
internal uint SceneEventId;
internal Action<uint> EventAction;
/// <summary>
/// Used server-side for integration testing in order to
/// invoke the SceneEventProgress once done loading
/// </summary>
internal Action Completed;
internal void Invoke()
{
Completed?.Invoke();
EventAction.Invoke(SceneEventId);
}
}
Expand Down
Loading