Skip to content
Open
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
8 changes: 8 additions & 0 deletions com.unity.netcode.gameobjects/Editor/Icons.meta

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions com.unity.netcode.gameobjects/Editor/Icons/NOBridgeIcon.png.meta

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

12 changes: 3 additions & 9 deletions com.unity.netcode.gameobjects/Editor/NetworkBehaviourEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,8 @@ private void OnEnable()
/// </summary>
/// <param name="transform">The current <see cref="Transform"/> we are inspecting for a parent</param>
/// <returns>the root parent for the first <see cref="Transform"/> passed into the method</returns>
public static Transform GetRootParentTransform(Transform transform)
{
if (transform.parent == null || transform.parent == transform)
{
return transform;
}
return GetRootParentTransform(transform.parent);
}
[Obsolete("Use transform.root instead", true)]
public static Transform GetRootParentTransform(Transform transform) => transform.root;

/// <summary>
/// Used to determine if a GameObject has one or more NetworkBehaviours but
Expand All @@ -358,7 +352,7 @@ public static void CheckForNetworkObject(GameObject gameObject, bool networkObje
}

// Now get the root parent transform to the current GameObject (or itself)
var rootTransform = GetRootParentTransform(gameObject.transform);
var rootTransform = gameObject.transform.root;
if (!rootTransform.TryGetComponent<NetworkManager>(out var networkManager))
{
networkManager = rootTransform.GetComponentInChildren<NetworkManager>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma warning disable IDE0005
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.Collections;
#if MULTIPLAYER_TOOLS && (DEVELOPMENT_BUILD || UNITY_EDITOR || UNITY_MP_TOOLS_NET_STATS_MONITOR_ENABLED_IN_RELEASE)
using System.Runtime.CompilerServices;
#endif
using UnityEngine;
#pragma warning restore IDE0005

Expand Down
14 changes: 12 additions & 2 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,10 @@ internal bool NetworkManagerCheckForParent(bool ignoreNetworkManagerCache = fals
#if UNITY_EDITOR
var isParented = NetworkManagerHelper.NotifyUserOfNestedNetworkManager(this, ignoreNetworkManagerCache);
#else
var isParented = transform.root != transform;
var isParented = transform.parent != null;
if (isParented)
{
throw new Exception(GenerateNestedNetworkManagerMessage(transform));
Log.Error(new Context(LogLevel.Error, GenerateNestedNetworkManagerMessage(transform)));
}
#endif
return isParented;
Expand All @@ -1029,7 +1029,17 @@ internal static string GenerateNestedNetworkManagerMessage(Transform transform)
/// </summary>
private void OnTransformParentChanged()
{
#if UNITY_EDITOR
// During editor playmode, we log the message as a dialog box
// and that script sets the parent back to root/null.
NetworkManagerCheckForParent();
#else
if (NetworkManagerCheckForParent())
{
// During runtime, we log the message and set our parent back to root/null.
transform.parent = null;
}
#endif
}

/// <summary>
Expand Down
33 changes: 14 additions & 19 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
using Unity.Netcode.Runtime;
#if UNITY_EDITOR
using UnityEditor;
#if UNITY_2021_2_OR_NEWER
using UnityEditor.SceneManagement;
#else
using UnityEditor.Experimental.SceneManagement;
#endif
#endif
using UnityEngine;
using UnityEngine.SceneManagement;
Expand Down Expand Up @@ -2665,7 +2661,7 @@ internal void InvokeBehaviourNetworkSpawn()
childBehaviour.InternalOnNetworkSpawn();
}

// After initialization, we can then invoke OnNetworkSpawn on each child NetworkBehaviour.
// After internally spawning, we can then invoke OnNetworkSpawn on each child NetworkBehaviour.
foreach (var childBehaviour in ChildNetworkBehaviours.Values)
{
if (!childBehaviour.gameObject.activeInHierarchy)
Expand Down Expand Up @@ -2740,6 +2736,7 @@ internal string GenerateDisabledNetworkBehaviourWarning(NetworkBehaviour network
}

internal Dictionary<ushort, NetworkBehaviour> ChildNetworkBehaviours;

internal bool InitializeChildNetworkBehaviours()
{
ChildNetworkBehaviours = new Dictionary<ushort, NetworkBehaviour>();
Expand Down Expand Up @@ -2770,9 +2767,7 @@ internal bool InitializeChildNetworkBehaviours()
networkTransform.IsNested = networkTransform.gameObject != gameObject;
NetworkTransforms.Add(networkTransform);
}

#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D

var rigidbodyBase = behaviour as NetworkRigidbodyBase;
if (rigidbodyBase != null)
{
Expand Down Expand Up @@ -2914,18 +2909,18 @@ internal struct SerializedObject
public ulong OwnerClientId;
public ushort OwnershipFlags;

private const ushort k_IsPlayerObject = 0x001;
private const ushort k_HasParent = 0x002;
private const ushort k_IsSceneObject = 0x004;
private const ushort k_HasTransform = 0x008;
private const ushort k_IsLatestParentSet = 0x010;
private const ushort k_WorldPositionStays = 0x020;
private const ushort k_DestroyWithScene = 0x040;
private const ushort k_DontDestroyWithOwner = 0x080;
private const ushort k_HasOwnershipFlags = 0x100;
private const ushort k_SyncObservers = 0x200;
private const ushort k_SpawnWithObservers = 0x400;
private const ushort k_HasInstantiationData = 0x800;
private const ushort k_IsPlayerObject = 0x0001;
private const ushort k_HasParent = 0x0002;
private const ushort k_IsSceneObject = 0x0004;
private const ushort k_HasTransform = 0x0008;
private const ushort k_IsLatestParentSet = 0x0010;
private const ushort k_WorldPositionStays = 0x0020;
private const ushort k_DestroyWithScene = 0x0040;
private const ushort k_DontDestroyWithOwner = 0x0080;
private const ushort k_HasOwnershipFlags = 0x0100;
private const ushort k_SyncObservers = 0x0200;
private const ushort k_SpawnWithObservers = 0x0400;
private const ushort k_HasInstantiationData = 0x0800;

public bool IsPlayerObject;
public bool HasParent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,9 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
}
var spawnedNetworkObject = NetworkObject.Deserialize(serializedObject, InternalBuffer, networkManager);

var noStop = InternalBuffer.Position;
if (EnableSerializationLogs)
{
var noStop = InternalBuffer.Position;
builder.AppendLine($"[Head: {noStart}][Tail: {noStop}][Size: {noStop - noStart}][{spawnedNetworkObject.name}][NID-{spawnedNetworkObject.NetworkObjectId}][Children: {spawnedNetworkObject.ChildNetworkBehaviours.Count}]");
LogArray(InternalBuffer.ToArray(), noStart, noStop, builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,11 @@ public void PlayerIsMoving(float movementDirection)
}
}

private Transform GetRootParentTransform(Transform transform)
{
if (transform.parent != null)
{
return GetRootParentTransform(transform.parent);
}
return transform;
}

protected override void OnNetworkPostSpawn()
{
if (CanCommitToTransform)
{
m_RootParentTransform = GetRootParentTransform(transform);
m_RootParentTransform = transform.root;
if (RandomizeScale)
{
transform.localScale = transform.localScale * Random.Range(0.5f, 1.5f);
Expand Down