com.unity.netcode.gameobjects@1.7.0

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).

## [1.7.0] - 2023-10-11

### Added

- exposed NetworkObject.GetNetworkBehaviourAtOrderIndex as a public API (#2724)
- Added context menu tool that provides users with the ability to quickly update the GlobalObjectIdHash value for all in-scene placed prefab instances that were created prior to adding a NetworkObject component to it. (#2707)
- Added methods NetworkManager.SetPeerMTU and NetworkManager.GetPeerMTU to be able to set MTU sizes per-peer (#2676)
- Added `GenerateSerializationForGenericParameterAttribute`, which can be applied to user-created Network Variable types to ensure the codegen generates serialization for the generic types they wrap. (#2694)
- Added `GenerateSerializationForTypeAttribute`, which can be applied to any class or method to ensure the codegen generates serialization for the specific provided type. (#2694)
- Exposed `NetworkVariableSerialization<T>.Read`, `NetworkVariableSerialization<T>.Write`, `NetworkVariableSerialization<T>.AreEqual`, and `NetworkVariableSerialization<T>.Duplicate` to further support the creation of user-created network variables by allowing users to access the generated serialization methods and serialize generic types efficiently without boxing. (#2694)
- Added `NetworkVariableBase.MarkNetworkBehaviourDirty` so that user-created network variable types can mark their containing `NetworkBehaviour` to be processed by the update loop. (#2694)

### Fixed

- Fixed issue where the server side `NetworkSceneManager` instance was not adding the currently active scene to its list of scenes loaded. (#2723)
- Generic NetworkBehaviour types no longer result in compile errors or runtime errors (#2720)
- Rpcs within Generic NetworkBehaviour types can now serialize parameters of the class's generic types (but may not have generic types of their own) (#2720)
- Errors are no longer thrown when entering play mode with domain reload disabled (#2720)
- NetworkSpawn is now correctly called each time when entering play mode with scene reload disabled (#2720)
- NetworkVariables of non-integer types will no longer break the inspector (#2714)
- NetworkVariables with NonSerializedAttribute will not appear in the inspector (#2714)
- Fixed issue where `UnityTransport` would attempt to establish WebSocket connections even if using UDP/DTLS Relay allocations when the build target was WebGL. This only applied to working in the editor since UDP/DTLS can't work in the browser. (#2695)
- Fixed issue where a `NetworkBehaviour` component's `OnNetworkDespawn` was not being invoked on the host-server side for an in-scene placed `NetworkObject` when a scene was unloaded (during a scene transition) and the `NetworkBehaviour` component was positioned/ordered before the `NetworkObject` component. (#2685)
- Fixed issue where `SpawnWithObservers` was not being honored when `NetworkConfig.EnableSceneManagement` was disabled. (#2682)
- Fixed issue where `NetworkAnimator` was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674)
- Fixed "writing past the end of the buffer" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized. (#2670)
- Fixed issue where generation of the `DefaultNetworkPrefabs` asset was not enabled by default. (#2662)
- Fixed issue where the `GlobalObjectIdHash` value could be updated but the asset not marked as dirty. (#2662)
- Fixed issue where the `GlobalObjectIdHash` value of a (network) prefab asset could be assigned an incorrect value when editing the prefab in a temporary scene. (#2662)
- Fixed issue where the `GlobalObjectIdHash` value generated after creating a (network) prefab from an object constructed within the scene would not be the correct final value in a stand alone build. (#2662)

### Changed

- Updated dependency on `com.unity.transport` to version 1.4.0. (#2716)
This commit is contained in:
Unity Technologies
2023-10-11 00:00:00 +00:00
parent b3bd4727ab
commit ffef45b50f
43 changed files with 1783 additions and 322 deletions

View File

@@ -499,6 +499,10 @@ namespace Unity.Netcode.Components
/// <remarks>
/// When there is no change in an updated state's position then there are no values to return.
/// Checking for <see cref="HasPositionChange"/> is one way to detect this.
/// When used with half precision it returns the half precision delta position state update
/// which will not be the full position.
/// To get a NettworkTransform's full position, use <see cref="GetSpaceRelativePosition(bool)"/> and
/// pass true as the parameter.
/// </remarks>
/// <returns><see cref="Vector3"/></returns>
public Vector3 GetPosition()
@@ -1110,7 +1114,16 @@ namespace Unity.Netcode.Components
}
else
{
return m_CurrentPosition;
// When half float precision is enabled, get the NetworkDeltaPosition's full position
if (UseHalfFloatPrecision)
{
return m_HalfPositionState.GetFullPosition();
}
else
{
// Otherwise, just get the current position
return m_CurrentPosition;
}
}
}
@@ -1393,6 +1406,8 @@ namespace Unity.Netcode.Components
{
}
// Tracks the last tick a state update was sent (see further below)
private int m_LastTick;
/// <summary>
/// Authoritative side only
/// If there are any transform delta states, this method will synchronize the
@@ -1411,11 +1426,27 @@ namespace Unity.Netcode.Components
if (ApplyTransformToNetworkStateWithInfo(ref m_LocalAuthoritativeNetworkState, ref transformToCommit, synchronize))
{
m_LocalAuthoritativeNetworkState.LastSerializedSize = m_OldState.LastSerializedSize;
OnAuthorityPushTransformState(ref m_LocalAuthoritativeNetworkState);
// Make sure our network tick is incremented
if (m_LastTick == m_LocalAuthoritativeNetworkState.NetworkTick && !m_LocalAuthoritativeNetworkState.IsTeleportingNextFrame)
{
// When running in authority and a remote client is the owner, the client can hit a perfect window of time where
// it is still on the previous network tick (as a count) but still have had the tick event triggered.
// (This is cheaper than calculating the exact tick each time and only can occur on clients)
if (!IsServer)
{
m_LocalAuthoritativeNetworkState.NetworkTick = m_LocalAuthoritativeNetworkState.NetworkTick + 1;
}
else
{
NetworkLog.LogError($"[NT TICK DUPLICATE] Server already sent an update on tick {m_LastTick} and is attempting to send again on the same network tick!");
}
}
m_LastTick = m_LocalAuthoritativeNetworkState.NetworkTick;
// Update the state
UpdateTransformState();
OnAuthorityPushTransformState(ref m_LocalAuthoritativeNetworkState);
m_LocalAuthoritativeNetworkState.IsTeleportingNextFrame = false;
}
}
@@ -2209,6 +2240,7 @@ namespace Unity.Netcode.Components
m_HalfPositionState.HalfVector3.Axis = m_LocalAuthoritativeNetworkState.NetworkDeltaPosition.HalfVector3.Axis;
// and update our target position
m_TargetPosition = m_HalfPositionState.ToVector3(newState.NetworkTick);
m_LocalAuthoritativeNetworkState.NetworkDeltaPosition.CurrentBasePosition = m_HalfPositionState.CurrentBasePosition;
m_LocalAuthoritativeNetworkState.CurrentPosition = m_TargetPosition;
}
@@ -2455,6 +2487,9 @@ namespace Unity.Netcode.Components
// Update any changes to the transform
var transformSource = transform;
OnUpdateAuthoritativeState(ref transformSource);
m_CurrentPosition = GetSpaceRelativePosition();
m_TargetPosition = GetSpaceRelativePosition();
}
else
{
@@ -2466,9 +2501,6 @@ namespace Unity.Netcode.Components
}
}
/// <inheritdoc/>
public override void OnNetworkSpawn()
{
@@ -2510,24 +2542,25 @@ namespace Unity.Netcode.Components
}
/// <inheritdoc/>
public override void OnGainedOwnership()
public override void OnLostOwnership()
{
// Only initialize if we gained ownership
if (OwnerClientId == NetworkManager.LocalClientId)
{
Initialize();
}
base.OnLostOwnership();
}
/// <inheritdoc/>
public override void OnLostOwnership()
public override void OnGainedOwnership()
{
// Only initialize if we are not authority and lost
// ownership
if (OwnerClientId != NetworkManager.LocalClientId)
base.OnGainedOwnership();
}
protected override void OnOwnershipChanged(ulong previous, ulong current)
{
// If we were the previous owner or the newly assigned owner then reinitialize
if (current == NetworkManager.LocalClientId || previous == NetworkManager.LocalClientId)
{
Initialize();
}
base.OnOwnershipChanged(previous, current);
}
/// <summary>
@@ -2552,6 +2585,7 @@ namespace Unity.Netcode.Components
}
/// <summary>
/// Initializes NetworkTransform when spawned and ownership changes.
/// </summary>
@@ -2572,7 +2606,8 @@ namespace Unity.Netcode.Components
{
m_HalfPositionState = new NetworkDeltaPosition(currentPosition, NetworkManager.NetworkTickSystem.ServerTime.Tick, math.bool3(SyncPositionX, SyncPositionY, SyncPositionZ));
}
m_CurrentPosition = currentPosition;
m_TargetPosition = currentPosition;
// Authority only updates once per network tick
NetworkManager.NetworkTickSystem.Tick -= NetworkTickSystem_Tick;
NetworkManager.NetworkTickSystem.Tick += NetworkTickSystem_Tick;
@@ -2835,6 +2870,13 @@ namespace Unity.Netcode.Components
/// <param name="messagePayload">serialzied <see cref="NetworkTransformState"/></param>
private void TransformStateUpdate(ulong senderId, FastBufferReader messagePayload)
{
if (!OnIsServerAuthoritative() && IsServer && OwnerClientId == NetworkManager.ServerClientId)
{
// Ownership must have changed, ignore any additional pending messages that might have
// come from a previous owner client.
return;
}
// Forward owner authoritative messages before doing anything else
if (IsServer && !OnIsServerAuthoritative())
{
@@ -2856,6 +2898,7 @@ namespace Unity.Netcode.Components
/// <param name="messagePayload">the owner state message payload</param>
private unsafe void ForwardStateUpdateMessage(FastBufferReader messagePayload)
{
var serverAuthoritative = OnIsServerAuthoritative();
var currentPosition = messagePayload.Position;
var messageSize = messagePayload.Length - currentPosition;
var writer = new FastBufferWriter(messageSize, Allocator.Temp);
@@ -2867,7 +2910,7 @@ namespace Unity.Netcode.Components
for (int i = 0; i < clientCount; i++)
{
var clientId = NetworkManager.ConnectionManager.ConnectedClientsList[i].ClientId;
if (!OnIsServerAuthoritative() && (NetworkManager.ServerClientId == clientId || clientId == OwnerClientId))
if (NetworkManager.ServerClientId == clientId || (!serverAuthoritative && clientId == OwnerClientId))
{
continue;
}