com.unity.netcode.gameobjects@1.0.0-pre.10
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.10] - 2022-06-21 ### Added - Added a new `OnTransportFailure` callback to `NetworkManager`. This callback is invoked when the manager's `NetworkTransport` encounters an unrecoverable error. Transport failures also cause the `NetworkManager` to shut down. Currently, this is only used by `UnityTransport` to signal a timeout of its connection to the Unity Relay servers. (#1994) - Added `NetworkEvent.TransportFailure`, which can be used by implementations of `NetworkTransport` to signal to `NetworkManager` that an unrecoverable error was encountered. (#1994) - Added test to ensure a warning occurs when nesting NetworkObjects in a NetworkPrefab (#1969) - Added `NetworkManager.RemoveNetworkPrefab(...)` to remove a prefab from the prefabs list (#1950) ### Changed - Updated `UnityTransport` dependency on `com.unity.transport` to 1.1.0. (#2025) - (API Breaking) `ConnectionApprovalCallback` is no longer an `event` and will not allow more than 1 handler registered at a time. Also, `ConnectionApprovalCallback` is now a `Func<>` taking `ConnectionApprovalRequest` in and returning `ConnectionApprovalResponse` back out (#1972) ### Removed ### Fixed - Fixed issue where dynamically spawned `NetworkObject`s could throw an exception if the scene of origin handle was zero (0) and the `NetworkObject` was already spawned. (#2017) - Fixed issue where `NetworkObject.Observers` was not being cleared when despawned. (#2009) - Fixed `NetworkAnimator` could not run in the server authoritative mode. (#2003) - Fixed issue where late joining clients would get a soft synchronization error if any in-scene placed NetworkObjects were parented under another `NetworkObject`. (#1985) - Fixed issue where `NetworkBehaviourReference` would throw a type cast exception if using `NetworkBehaviourReference.TryGet` and the component type was not found. (#1984) - Fixed `NetworkSceneManager` was not sending scene event notifications for the currently active scene and any additively loaded scenes when loading a new scene in `LoadSceneMode.Single` mode. (#1975) - Fixed issue where one or more clients disconnecting during a scene event would cause `LoadEventCompleted` or `UnloadEventCompleted` to wait until the `NetworkConfig.LoadSceneTimeOut` period before being triggered. (#1973) - Fixed issues when multiple `ConnectionApprovalCallback`s were registered (#1972) - Fixed a regression in serialization support: `FixedString`, `Vector2Int`, and `Vector3Int` types can now be used in NetworkVariables and RPCs again without requiring a `ForceNetworkSerializeByMemcpy<>` wrapper. (#1961) - Fixed generic types that inherit from NetworkBehaviour causing crashes at compile time. (#1976) - Fixed endless dialog boxes when adding a `NetworkBehaviour` to a `NetworkManager` or vice-versa. (#1947) - Fixed `NetworkAnimator` issue where it was only synchronizing parameters if the layer or state changed or was transitioning between states. (#1946) - Fixed `NetworkAnimator` issue where when it did detect a parameter had changed it would send all parameters as opposed to only the parameters that changed. (#1946) - Fixed `NetworkAnimator` issue where it was not always disposing the `NativeArray` that is allocated when spawned. (#1946) - Fixed `NetworkAnimator` issue where it was not taking the animation speed or state speed multiplier into consideration. (#1946) - Fixed `NetworkAnimator` issue where it was not properly synchronizing late joining clients if they joined while `Animator` was transitioning between states. (#1946) - Fixed `NetworkAnimator` issue where the server was not relaying changes to non-owner clients when a client was the owner. (#1946) - Fixed issue where the `PacketLoss` metric for tools would return the packet loss over a connection lifetime instead of a single frame. (#2004)
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
@@ -75,7 +76,7 @@ namespace Unity.Netcode
|
||||
public bool IsPlayerObject { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the object is the the personal clients player object
|
||||
/// Gets if the object is the personal clients player object
|
||||
/// </summary>
|
||||
public bool IsLocalPlayer => NetworkManager != null && IsPlayerObject && OwnerClientId == NetworkManager.LocalClientId;
|
||||
|
||||
@@ -151,6 +152,7 @@ namespace Unity.Netcode
|
||||
#endif
|
||||
}
|
||||
|
||||
private readonly HashSet<ulong> m_EmptyULongHashSet = new HashSet<ulong>();
|
||||
/// <summary>
|
||||
/// Returns Observers enumerator
|
||||
/// </summary>
|
||||
@@ -159,7 +161,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
if (!IsSpawned)
|
||||
{
|
||||
throw new SpawnStateException("Object is not spawned");
|
||||
return m_EmptyULongHashSet.GetEnumerator();
|
||||
}
|
||||
|
||||
return Observers.GetEnumerator();
|
||||
@@ -174,15 +176,62 @@ namespace Unity.Netcode
|
||||
{
|
||||
if (!IsSpawned)
|
||||
{
|
||||
throw new SpawnStateException("Object is not spawned");
|
||||
return false;
|
||||
}
|
||||
return Observers.Contains(clientId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In the event the scene of origin gets unloaded, we keep
|
||||
/// the most important part to uniquely identify in-scene
|
||||
/// placed NetworkObjects
|
||||
/// </summary>
|
||||
internal int SceneOriginHandle = 0;
|
||||
|
||||
private Scene m_SceneOrigin;
|
||||
/// <summary>
|
||||
/// The scene where the NetworkObject was first instantiated
|
||||
/// Note: Primarily for in-scene placed NetworkObjects
|
||||
/// We need to keep track of the original scene of origin for
|
||||
/// the NetworkObject in order to be able to uniquely identify it
|
||||
/// using the scene of origin's handle.
|
||||
/// </summary>
|
||||
internal Scene SceneOrigin
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SceneOrigin;
|
||||
}
|
||||
|
||||
return Observers.Contains(clientId);
|
||||
set
|
||||
{
|
||||
// The scene origin should only be set once.
|
||||
// Once set, it should never change.
|
||||
if (SceneOriginHandle == 0 && value.IsValid() && value.isLoaded)
|
||||
{
|
||||
m_SceneOrigin = value;
|
||||
SceneOriginHandle = value.handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to return the correct scene handle
|
||||
/// Note: Do not use this within NetworkSpawnManager.SpawnNetworkObjectLocallyCommon
|
||||
/// </summary>
|
||||
internal int GetSceneOriginHandle()
|
||||
{
|
||||
if (SceneOriginHandle == 0 && IsSpawned && IsSceneObject != false)
|
||||
{
|
||||
throw new Exception($"{nameof(GetSceneOriginHandle)} called when {nameof(SceneOriginHandle)} is still zero but the {nameof(NetworkObject)} is already spawned!");
|
||||
}
|
||||
return SceneOriginHandle != 0 ? SceneOriginHandle : gameObject.scene.handle;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
SetCachedParent(transform.parent);
|
||||
SceneOrigin = gameObject.scene;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -285,7 +334,8 @@ namespace Unity.Netcode
|
||||
|
||||
var message = new DestroyObjectMessage
|
||||
{
|
||||
NetworkObjectId = NetworkObjectId
|
||||
NetworkObjectId = NetworkObjectId,
|
||||
DestroyGameObject = true
|
||||
};
|
||||
// Send destroy call
|
||||
var size = NetworkManager.SendMessage(ref message, NetworkDelivery.ReliableSequenced, clientId);
|
||||
@@ -372,7 +422,7 @@ namespace Unity.Netcode
|
||||
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++)
|
||||
{
|
||||
@@ -865,16 +915,17 @@ namespace Unity.Netcode
|
||||
public NetworkObject OwnerObject;
|
||||
public ulong TargetClientId;
|
||||
|
||||
public int NetworkSceneHandle;
|
||||
|
||||
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.");
|
||||
}
|
||||
@@ -900,6 +951,16 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
// 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.GetSceneOriginHandle());
|
||||
}
|
||||
|
||||
OwnerObject.WriteNetworkVariableData(writer, TargetClientId);
|
||||
}
|
||||
|
||||
@@ -910,10 +971,12 @@ namespace Unity.Netcode
|
||||
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.");
|
||||
}
|
||||
@@ -937,6 +1000,16 @@ namespace Unity.Netcode
|
||||
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.ReadValueSafe(out NetworkSceneHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1006,6 +1079,7 @@ namespace Unity.Netcode
|
||||
Vector3? position = null;
|
||||
Quaternion? rotation = null;
|
||||
ulong? parentNetworkId = null;
|
||||
int? networkSceneHandle = null;
|
||||
|
||||
if (sceneObject.Header.HasTransform)
|
||||
{
|
||||
@@ -1018,10 +1092,15 @@ namespace Unity.Netcode
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user