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
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- Added `NetworkConfig.TransformSyncMode`, which determines whether `NetworkTransform` instances detect and synchronize their state individually or as a single batched message per tick. It is set per `NetworkManager` under "Transform Synchronization" in the inspector or from script before a session starts, and the value the session starts with applies for the duration of that session. Every peer in a session has to use the same mode, which the connection configuration hash enforces. (#4235)
- Added alignment of the Netcode for Entities tick rates with `NetworkConfig.TickRate` when a session carrying `GhostObject` prefabs is started, so `GhostObject` updates land on the same interval as the rest of Netcode for GameObjects. (#4144)
- Added `NetworkConfig.AutoConfigureSnapshotSize`, enabled by default, which sets the Netcode for Entities snapshot packet size to 4096 bytes when a session carrying `GhostObject` prefabs is started. Netcode for Entities defaults to a single MTU, which updates `GhostObject`s well below the tick rate at the instance counts Netcode for GameObjects projects typically run. Disable it to manage the value yourself. (#4144)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ private void DisplayNetworkTransformProperties()
EditorGUILayout.Space();
EditorGUILayout.LabelField("Delivery", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_TickSyncChildren);

// UseUnreliableDeltas only applies to per instance synchronization mode, but the mode is authored on
// the NetworkManager that will run this instance, which a prefab cannot know. So it is always drawn
// and the runtime ignores it under the batched mode, where delivery is determined per state update
// as opposed to per component.
// If both are set from a previous configuration, then SwitchTransformSpaceWhenParented takes
// precedence.
if (networkTransform.UseUnreliableDeltas && networkTransform.SwitchTransformSpaceWhenParented)
Expand All @@ -242,6 +247,7 @@ private void DisplayNetworkTransformProperties()
EditorGUILayout.Space();
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel);

// SwitchTransformSpaceWhenParented is only constrained by UseUnreliableDeltas while the latter applies.
SetGUIActive(!networkTransform.UseUnreliableDeltas);
if (networkTransform.UseUnreliableDeltas)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Unity.Burst;
using Unity.Collections;
using UnityEngine.Jobs;
using static Unity.Netcode.Components.NetworkTransform;

namespace Unity.Netcode.Components
{
/// <summary>
/// Motion Authority Only:
/// Detects <see cref="NetworkTransform"/> state changes for every registered instance in a parallel job.
/// </summary>
/// <remarks>
/// <see cref="CheckForStateChange(ref NetworkTransformState, ref NetworkDeltaPosition, ref TransformDeltaConfig, in TransformSample, bool, bool, bool)"/>
/// is the common method used for both per instance, runs on the main thread, and batched modes. This assures both paths detect changes in state identically.
/// </remarks>
[BurstCompile]
internal struct DetectTransformDeltaJob : IJobParallelForTransform
{
/// <summary>
/// The per instance input and output, parallel to the job's scheduled transforms.
/// </summary>
public NativeArray<TransformDeltaEntry> Entries;

/// <summary>
/// This job's primary entry point.
/// </summary>
/// <remarks>
/// TODO: Investigate ways to work around the fact that a Rigidbody's position and rotation cannot
/// be sampled from a job. As such, any NetworkTransform that is using Rigidbody for motion will
/// use the <see cref="UnityEngine.GameObject.transform"/> to detect changes in position and rotation
/// states on the authority side.
/// </remarks>
/// <param name="index">Index for the transform in question.</param>
/// <param name="transform">The job safe <see cref="TransformAccess"/></param>
public void Execute(int index, TransformAccess transform)
{
if (!transform.isValid)
{
return;
}

var entry = Entries[index];
var flagStates = entry.State.FlagStates;
// Only ResolveTransformSpace can raise this on the batched path. The one caller that forces a full
// state update does so from CommitDetectedState on the main thread, after this job has run.
var forceState = false;

// Resolve the transform space before sampling, otherwise the wrong set of values gets compared.
var transformSpaceChanged = ResolveTransformSpace(ref entry.Config, ref flagStates, entry.TransformHasParent, false, ref forceState);
entry.State.FlagStates = flagStates;

var rotation = entry.Config.InLocalSpace ? transform.localRotation : transform.rotation;
entry.Sample.Position = entry.Config.InLocalSpace ? transform.localPosition : transform.position;
entry.Sample.Rotation = rotation;
entry.Sample.RotAngles = NetworkTransformMath.EulerAngles(rotation);
entry.Sample.Scale = transform.localScale;

entry.IsDirty = CheckForStateChange(ref entry.State, ref entry.HalfPositionState, ref entry.Config,
entry.Sample, false, forceState, transformSpaceChanged);

Entries[index] = entry;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ internal struct BufferedItemNative
/// <br />
/// The smooth parenting transition flag, <see cref="NetworkTransform.SwitchTransformSpaceWhenParented"/>,
/// is excluded from this state as it is handled differently.<br />
/// - <see cref="NativeInterpolator.ConvertSpace"/> provides additional details on this.
/// - <see cref="NativeInterpolator.ConvertSpace"/> provides additional details on this. <br />
/// - <see cref="NetworkTransformStateManager.ConvertInterpolationSpace"/> is where this happens.
/// </remarks>
internal struct NativeInterpolatorState
{
Expand Down
Loading