Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.0.0-pre.7] - 2022-04-01

### 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)
- `UnityTransport` settings can now be set programmatically. (#1845)
- `FastBufferWriter` and Reader IsInitialized property. (#1859)

### Changed

- Updated `UnityTransport` dependency on `com.unity.transport` to 1.0.0 (#1849)

### Removed

- Removed `SnapshotSystem` (#1852)
- Removed `com.unity.modules.animation`, `com.unity.modules.physics` and `com.unity.modules.physics2d` dependencies from the package (#1812)
- Removed `com.unity.collections` dependency from the package (#1849)

### Fixed
- Fixed in-scene placed NetworkObjects not being found/ignored after a client disconnects and then reconnects. (#1850)
- Fixed issue where `UnityTransport` send queues were not flushed when calling `DisconnectLocalClient` or `DisconnectRemoteClient`. (#1847)
- Fixed NetworkBehaviour dependency verification check for an existing NetworkObject not searching from root parent transform relative GameObject. (#1841)
- Fixed issue where entries were not being removed from the NetworkSpawnManager.OwnershipToObjectsTable. (#1838)
- Fixed ClientRpcs would always send to all connected clients by default as opposed to only sending to the NetworkObject's Observers list by default. (#1836)
- Fixed clarity for NetworkSceneManager client side notification when it receives a scene hash value that does not exist in its local hash table. (#1828)
- Fixed client throws a key not found exception when it times out using UNet or UTP. (#1821)
- Fixed network variable updates are no longer limited to 32,768 bytes when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled. The limits are now determined by what the transport can send in a message. (#1811)
- Fixed in-scene NetworkObjects get destroyed if a client fails to connect and shuts down the NetworkManager. (#1809)
- Fixed user never being notified in the editor that a NetworkBehaviour requires a NetworkObject to function properly. (#1808)
- Fixed PlayerObjects and dynamically spawned NetworkObjects not being added to the NetworkClient's OwnedObjects (#1801)
- Fixed issue where NetworkManager would continue starting even if the NetworkTransport selected failed. (#1780)
- Fixed issue when spawning new player if an already existing player exists it does not remove IsPlayer from the previous player (#1779)
- Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications (#1777)
- Fixed parenting warning printing for false positives (#1855)
  • Loading branch information
Unity Technologies committed Apr 1, 2022
1 parent 5b4aaa8 commit 60e2dab
Show file tree
Hide file tree
Showing 123 changed files with 5,741 additions and 3,409 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

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

## [1.0.0-pre.7] - 2022-04-01

### 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)
- `UnityTransport` settings can now be set programmatically. (#1845)
- `FastBufferWriter` and Reader IsInitialized property. (#1859)

### Changed

- Updated `UnityTransport` dependency on `com.unity.transport` to 1.0.0 (#1849)

### Removed

- Removed `SnapshotSystem` (#1852)
- Removed `com.unity.modules.animation`, `com.unity.modules.physics` and `com.unity.modules.physics2d` dependencies from the package (#1812)
- Removed `com.unity.collections` dependency from the package (#1849)

### Fixed
- Fixed in-scene placed NetworkObjects not being found/ignored after a client disconnects and then reconnects. (#1850)
- Fixed issue where `UnityTransport` send queues were not flushed when calling `DisconnectLocalClient` or `DisconnectRemoteClient`. (#1847)
- Fixed NetworkBehaviour dependency verification check for an existing NetworkObject not searching from root parent transform relative GameObject. (#1841)
- Fixed issue where entries were not being removed from the NetworkSpawnManager.OwnershipToObjectsTable. (#1838)
- Fixed ClientRpcs would always send to all connected clients by default as opposed to only sending to the NetworkObject's Observers list by default. (#1836)
- Fixed clarity for NetworkSceneManager client side notification when it receives a scene hash value that does not exist in its local hash table. (#1828)
- Fixed client throws a key not found exception when it times out using UNet or UTP. (#1821)
- Fixed network variable updates are no longer limited to 32,768 bytes when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled. The limits are now determined by what the transport can send in a message. (#1811)
- Fixed in-scene NetworkObjects get destroyed if a client fails to connect and shuts down the NetworkManager. (#1809)
- Fixed user never being notified in the editor that a NetworkBehaviour requires a NetworkObject to function properly. (#1808)
- Fixed PlayerObjects and dynamically spawned NetworkObjects not being added to the NetworkClient's OwnedObjects (#1801)
- Fixed issue where NetworkManager would continue starting even if the NetworkTransport selected failed. (#1780)
- Fixed issue when spawning new player if an already existing player exists it does not remove IsPlayer from the previous player (#1779)
- Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications (#1777)
- Fixed parenting warning printing for false positives (#1855)

## [1.0.0-pre.6] - 2022-03-02

### Added
Expand Down Expand Up @@ -33,6 +70,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed OwnedObjects not being properly modified when using ChangeOwnership (#1731)
- Improved performance in NetworkAnimator (#1735)
- Removed the "always sync" network animator (aka "autosend") parameters (#1746)
- Fixed in-scene placed NetworkObjects not respawning after shutting down the NetworkManager and then starting it back up again (#1769)

## [1.0.0-pre.5] - 2022-01-26

Expand Down
11 changes: 10 additions & 1 deletion Components/Interpolator/BufferedLinearInterpolator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ public T Update(float deltaTime, double renderTime, double serverTime)

if (t < 0.0f)
{
throw new OverflowException($"t = {t} but must be >= 0. range {range}, RenderTime {renderTime}, Start time {m_StartTimeConsumed}, end time {m_EndTimeConsumed}");
// There is no mechanism to guarantee renderTime to not be before m_StartTimeConsumed
// This clamps t to a minimum of 0 and fixes issues with longer frames and pauses

if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
{
NetworkLog.LogError($"renderTime was before m_StartTimeConsumed. This should never happen. {nameof(renderTime)} is {renderTime}, {nameof(m_StartTimeConsumed)} is {m_StartTimeConsumed}");
}
t = 0.0f;
}

if (t > 3.0f) // max extrapolation
Expand Down Expand Up @@ -218,6 +225,8 @@ public void AddMeasurement(T newMeasurement, double sentTime)
{
m_LastBufferedItemReceived = new BufferedItem(newMeasurement, sentTime);
ResetTo(newMeasurement, sentTime);
// Next line keeps renderTime above m_StartTimeConsumed. Fixes pause/unpause issues
m_Buffer.Add(m_LastBufferedItemReceived);
}

return;
Expand Down
16 changes: 7 additions & 9 deletions Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#if COM_UNITY_MODULES_ANIMATION
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;

namespace Unity.Netcode.Components
{
/// <summary>
/// A prototype component for syncing animations
/// NetworkAnimator enables remote synchronization of <see cref="UnityEngine.Animator"/> state for on network objects.
/// </summary>
[AddComponentMenu("Netcode/" + nameof(NetworkAnimator))]
[RequireComponent(typeof(Animator))]
Expand Down Expand Up @@ -380,9 +381,7 @@ public void SetTrigger(string triggerName)
SetTrigger(Animator.StringToHash(triggerName));
}

/// <summary>
/// Sets the trigger for the associated animation. See note for SetTrigger(string)
/// </summary>
/// <inheritdoc cref="SetTrigger(string)" />
/// <param name="hash">The hash for the trigger to activate</param>
/// <param name="reset">If true, resets the trigger</param>
public void SetTrigger(int hash, bool reset = false)
Expand Down Expand Up @@ -413,21 +412,20 @@ public void SetTrigger(int hash, bool reset = false)
}

/// <summary>
/// Resets the trigger for the associated animation. See note for SetTrigger(string)
/// Resets the trigger for the associated animation. See <see cref="SetTrigger(string)">SetTrigger</see> for more on how triggers are special
/// </summary>
/// <param name="triggerName">The string name of the trigger to reset</param>
public void ResetTrigger(string triggerName)
{
ResetTrigger(Animator.StringToHash(triggerName));
}

/// <summary>
/// Resets the trigger for the associated animation. See note for SetTrigger(string)
/// </summary>
/// <param name="hash">The hash for the trigger to reset</param>
/// <inheritdoc cref="ResetTrigger(string)" path="summary" />
/// <param name="hash">The hash for the trigger to activate</param>
public void ResetTrigger(int hash)
{
SetTrigger(hash, true);
}
}
}
#endif // COM_UNITY_MODULES_ANIMATION
2 changes: 2 additions & 0 deletions Components/NetworkRigidbody.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if COM_UNITY_MODULES_PHYSICS
using UnityEngine;

namespace Unity.Netcode.Components
Expand Down Expand Up @@ -78,3 +79,4 @@ public override void OnNetworkDespawn()
}
}
}
#endif // COM_UNITY_MODULES_PHYSICS
2 changes: 2 additions & 0 deletions Components/NetworkRigidbody2D.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if COM_UNITY_MODULES_PHYSICS2D
using UnityEngine;

namespace Unity.Netcode.Components
Expand Down Expand Up @@ -78,3 +79,4 @@ public override void OnNetworkDespawn()
}
}
}
#endif // COM_UNITY_MODULES_PHYSICS2D
5 changes: 2 additions & 3 deletions Components/NetworkTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
/// If using different values, please use RPCs to write to the server. Netcode doesn't support client side network variable writing
/// </summary>
// This is public to make sure that users don't depend on this IsClient && IsOwner check in their code. If this logic changes in the future, we can make it invisible here
public bool CanCommitToTransform;
public bool CanCommitToTransform { get; protected set; }
protected bool m_CachedIsServer;
protected NetworkManager m_CachedNetworkManager;

Expand Down Expand Up @@ -691,7 +691,6 @@ private void OnNetworkStateChanged(NetworkTransformState oldState, NetworkTransf
{
if (!NetworkObject.IsSpawned)
{
// todo MTT-849 should never happen but yet it does! maybe revisit/dig after NetVar updates and snapshot system lands?
return;
}

Expand Down Expand Up @@ -785,7 +784,7 @@ private void Initialize()
{
m_ReplicatedNetworkState.SetDirty(true);
}
else
else if (m_Transform != null)
{
ApplyInterpolatedNetworkStateToTransform(m_ReplicatedNetworkState.Value, m_Transform);
}
Expand Down
19 changes: 18 additions & 1 deletion Components/com.unity.netcode.components.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@
"Unity.Netcode.Runtime",
"Unity.Collections"
],
"allowUnsafeCode": true
"allowUnsafeCode": true,
"versionDefines": [
{
"name": "com.unity.modules.animation",
"expression": "",
"define": "COM_UNITY_MODULES_ANIMATION"
},
{
"name": "com.unity.modules.physics",
"expression": "",
"define": "COM_UNITY_MODULES_PHYSICS"
},
{
"name": "com.unity.modules.physics2d",
"expression": "",
"define": "COM_UNITY_MODULES_PHYSICS2D"
}
]
}
23 changes: 0 additions & 23 deletions Editor/NetworkAnimatorEditor.cs

This file was deleted.

86 changes: 86 additions & 0 deletions Editor/NetworkBehaviourEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,91 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();
EditorGUI.EndChangeCheck();
}

/// <summary>
/// Invoked once when a NetworkBehaviour component is
/// displayed in the inspector view.
/// </summary>
private void OnEnable()
{
// 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);
}

internal const string AutoAddNetworkObjectIfNoneExists = "AutoAdd-NetworkObject-When-None-Exist";

public static Transform GetRootParentTransform(Transform transform)
{
if (transform.parent == null || transform.parent == transform)
{
return transform;
}
return GetRootParentTransform(transform.parent);
}

/// <summary>
/// Used to determine if a GameObject has one or more NetworkBehaviours but
/// does not already have a NetworkObject component. If not it will notify
/// the user that NetworkBehaviours require a NetworkObject.
/// </summary>
public static void CheckForNetworkObject(GameObject gameObject, bool networkObjectRemoved = false)
{
// If there are no NetworkBehaviours or no gameObject, then exit early
if (gameObject == null || (gameObject.GetComponent<NetworkBehaviour>() == null && gameObject.GetComponentInChildren<NetworkBehaviour>() == null))
{
return;
}

// Now get the root parent transform to the current GameObject (or itself)
var rootTransform = GetRootParentTransform(gameObject.transform);

// Otherwise, check to see if there is any NetworkObject from the root GameObject down to all children.
// If not, notify the user that NetworkBehaviours require that the relative GameObject has a NetworkObject component.
var networkObject = rootTransform.GetComponent<NetworkObject>();
if (networkObject == null)
{
networkObject = rootTransform.GetComponentInChildren<NetworkObject>();

if (networkObject == null)
{
// If we are removing a NetworkObject but there is still one or more NetworkBehaviour components
// and the user has already turned "Auto-Add NetworkObject" on when first notified about the requirement
// then just send a reminder to the user why the NetworkObject they just deleted seemingly "re-appeared"
// again.
if (networkObjectRemoved && EditorPrefs.HasKey(AutoAddNetworkObjectIfNoneExists) && EditorPrefs.GetBool(AutoAddNetworkObjectIfNoneExists))
{
Debug.LogWarning($"{gameObject.name} still has {nameof(NetworkBehaviour)}s and Auto-Add NetworkObjects is enabled. A NetworkObject is being added back to {gameObject.name}.");
Debug.Log($"To reset Auto-Add NetworkObjects: Select the Netcode->General->Reset Auto-Add NetworkObject menu item.");
}

// Notify and provide the option to add it one time, always add a NetworkObject, or do nothing and let the user manually add it
if (EditorUtility.DisplayDialog($"{nameof(NetworkBehaviour)}s require a {nameof(NetworkObject)}",
$"{gameObject.name} does not have a {nameof(NetworkObject)} component. Would you like to add one now?", "Yes", "No (manually add it)",
DialogOptOutDecisionType.ForThisMachine, AutoAddNetworkObjectIfNoneExists))
{
gameObject.AddComponent<NetworkObject>();
var activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(activeScene);
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(activeScene);
}
}
}
}

/// <summary>
/// This allows users to reset the Auto-Add NetworkObject preference
/// so the next time they add a NetworkBehaviour to a GameObject without
/// a NetworkObject it will display the dialog box again and not
/// automatically add a NetworkObject.
/// </summary>
[MenuItem("Netcode/General/Reset Auto-Add NetworkObject", false, 1)]
private static void ResetMultiplayerToolsTipStatus()
{
if (EditorPrefs.HasKey(AutoAddNetworkObjectIfNoneExists))
{
EditorPrefs.SetBool(AutoAddNetworkObjectIfNoneExists, false);
}
}
}
}
10 changes: 7 additions & 3 deletions Editor/NetworkManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ private void OnEnable()
m_NetworkPrefabsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(NetworkManager.NetworkConfig)).FindPropertyRelative(nameof(NetworkConfig.NetworkPrefabs)), true, true, true, true);
m_NetworkPrefabsList.elementHeightCallback = index =>
{
var networkPrefab = m_NetworkPrefabsList.serializedProperty.GetArrayElementAtIndex(index);
var networkOverrideProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.Override));
var networkOverrideInt = networkOverrideProp.enumValueIndex;
var networkOverrideInt = 0;
if (m_NetworkPrefabsList.count > 0)
{
var networkPrefab = m_NetworkPrefabsList.serializedProperty.GetArrayElementAtIndex(index);
var networkOverrideProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.Override));
networkOverrideInt = networkOverrideProp.enumValueIndex;
}

return 8 + (networkOverrideInt == 0 ? EditorGUIUtility.singleLineHeight : (EditorGUIUtility.singleLineHeight * 2) + 5);
};
Expand Down
Loading

0 comments on commit 60e2dab

Please sign in to comment.