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
14 changes: 7 additions & 7 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3736,7 +3736,13 @@ private void Start()

private void InitGhost()
{
if (!NetworkManager.IsListening)
if (!HasGhost || !NetworkObjectBridge || GhostAdapter.IsPrefab())
{
// Nothing to register
return;
}

if (!NetworkManager || !NetworkManager.IsListening)
{
if (NetworkManager.LogLevel == LogLevel.Developer)
{
Expand All @@ -3745,12 +3751,6 @@ private void InitGhost()
return;
}

if (!HasGhost || !NetworkObjectBridge || GhostAdapter.IsPrefab())
{
// Nothing to register
return;
}

// All instances with Ghosts are automatically registered
if (NetworkManager.LogLevel == LogLevel.Developer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,14 @@ internal NetworkObject GetNetworkObjectToSpawn(uint globalObjectIdHash, ulong ow
/// <returns>the instance of the <see cref="NetworkObject"/></returns>
internal NetworkObject InstantiateNetworkPrefab([NotNull] GameObject networkPrefab, uint prefabGlobalObjectIdHash, Vector3? position, Quaternion? rotation)
{
#if UNIFIED_NETCODE
// TODO-FixMe: NetCode.Netcode.Instance is a singleton and might cause issues
// assigning this.
if (networkPrefab.GetComponent<NetworkObject>().HasGhost)
{
NetCode.Netcode.Instance.m_ActiveWorld = NetworkManager.NetcodeWorld;
}
#endif
var gameObject = Object.Instantiate(networkPrefab);
var networkObject = gameObject.GetComponent<NetworkObject>();
if (networkObject == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,14 @@ protected void SpawnObjectInstance(NetworkObject networkObjectToSpawn, NetworkMa
/// <returns>GameObject instance spawned</returns>
private GameObject SpawnObject(NetworkObject prefabNetworkObject, NetworkManager owner, bool destroyWithScene = false, bool isPlayerObject = false)
{
#if UNIFIED_NETCODE
// TODO-FixMe: NetCode.Netcode.Instance is a singleton and might cause issues
// assigning this.
if (prefabNetworkObject.HasGhost)
{
NetCode.Netcode.Instance.m_ActiveWorld = owner.NetcodeWorld;
}
#endif
Assert.IsTrue(prefabNetworkObject.GlobalObjectIdHash > 0, $"{nameof(GameObject)} {prefabNetworkObject.name} has a {nameof(NetworkObject.GlobalObjectIdHash)} value of 0! Make sure to make it a valid prefab before trying to spawn!");
var newInstance = Object.Instantiate(prefabNetworkObject.gameObject);
var networkObjectToSpawn = newInstance.GetComponent<NetworkObject>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
#if UNIFIED_NETCODE
using Unity.NetCode;
#endif

namespace TestProject.RuntimeTests
{
Expand Down Expand Up @@ -75,6 +78,14 @@ private void SpawnRpc(RpcParams rpcParams = default)

private void Spawn(ulong ownerId)
{
#if UNIFIED_NETCODE
// TODO-FixMe: NetCode.Netcode.Instance is a singleton and might cause issues
// assigning this.
if (ObjectToSpawn.GetComponent<NetworkObject>().HasGhost)
{
Netcode.Instance.m_ActiveWorld = NetworkManager.NetcodeWorld;
}
#endif
var instance = Instantiate(ObjectToSpawn);
var networkObject = instance.GetComponent<NetworkObject>();
networkObject.SpawnWithOwnership(ownerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Unity.Mathematics",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"Unity.Netcode.Runtime.Tests"
"Unity.Netcode.Runtime.Tests",
"Unity.NetCode"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Loading