Skip to content

Commit 5cfc6c2

Browse files
update
Fixing some merge issues.
1 parent bae60bb commit 5cfc6c2

3 files changed

Lines changed: 52 additions & 42 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void UnifiedValidation()
394394
{
395395
// Keep moving until it can't go higher
396396
}
397-
397+
398398
EditorUtility.SetDirty(gameObject);
399399
}
400400
else if (HadBridge && !HasGhost && !NetworkObjectBridge)
@@ -2913,18 +2913,21 @@ internal struct SerializedObject
29132913
public ulong OwnerClientId;
29142914
public ushort OwnershipFlags;
29152915

2916-
private const ushort k_IsPlayerObject = 0x001;
2917-
private const ushort k_HasParent = 0x002;
2918-
private const ushort k_IsSceneObject = 0x004;
2919-
private const ushort k_HasTransform = 0x008;
2920-
private const ushort k_IsLatestParentSet = 0x010;
2921-
private const ushort k_WorldPositionStays = 0x020;
2922-
private const ushort k_DestroyWithScene = 0x040;
2923-
private const ushort k_DontDestroyWithOwner = 0x080;
2924-
private const ushort k_HasOwnershipFlags = 0x100;
2925-
private const ushort k_SyncObservers = 0x200;
2926-
private const ushort k_SpawnWithObservers = 0x400;
2927-
private const ushort k_HasInstantiationData = 0x800;
2916+
private const ushort k_IsPlayerObject = 0x0001;
2917+
private const ushort k_HasParent = 0x0002;
2918+
private const ushort k_IsSceneObject = 0x0004;
2919+
private const ushort k_HasTransform = 0x0008;
2920+
private const ushort k_IsLatestParentSet = 0x0010;
2921+
private const ushort k_WorldPositionStays = 0x0020;
2922+
private const ushort k_DestroyWithScene = 0x0040;
2923+
private const ushort k_DontDestroyWithOwner = 0x0080;
2924+
private const ushort k_HasOwnershipFlags = 0x0100;
2925+
private const ushort k_SyncObservers = 0x0200;
2926+
private const ushort k_SpawnWithObservers = 0x0400;
2927+
private const ushort k_HasInstantiationData = 0x0800;
2928+
#if UNIFIED_NETCODE
2929+
private const ushort k_HasGhost = 0x1000;
2930+
#endif
29282931

29292932
public bool IsPlayerObject;
29302933
public bool HasParent;
@@ -2952,6 +2955,9 @@ internal struct SerializedObject
29522955
public bool SpawnWithObservers;
29532956

29542957
public bool HasInstantiationData;
2958+
#if UNIFIED_NETCODE
2959+
public bool HasGhost;
2960+
#endif
29552961

29562962
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29572963
internal ushort GetBitsetRepresentation()
@@ -3001,10 +3007,19 @@ internal ushort GetBitsetRepresentation()
30013007
{
30023008
bitset |= k_SpawnWithObservers;
30033009
}
3010+
30043011
if (HasInstantiationData)
30053012
{
30063013
bitset |= k_HasInstantiationData;
30073014
}
3015+
3016+
#if UNIFIED_NETCODE
3017+
if (HasGhost)
3018+
{
3019+
bitset |= k_HasGhost;
3020+
}
3021+
3022+
#endif
30083023
return bitset;
30093024
}
30103025

@@ -3023,15 +3038,10 @@ internal void SetStateFromBitset(ushort bitset)
30233038
SyncObservers = (bitset & k_SyncObservers) != 0;
30243039
SpawnWithObservers = (bitset & k_SpawnWithObservers) != 0;
30253040
HasInstantiationData = (bitset & k_HasInstantiationData) != 0;
3026-
}
3027-
30283041
#if UNIFIED_NETCODE
3029-
public bool HasGhost
3030-
{
3031-
get => ByteUtility.GetBit(m_BitField, 12);
3032-
set => ByteUtility.SetBit(ref m_BitField, 12, value);
3033-
}
3042+
HasGhost = (bitset & k_HasGhost) != 0;
30343043
#endif
3044+
}
30353045

30363046
// When handling the initial synchronization of NetworkObjects,
30373047
// this will be populated with the known observers.

com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,23 +1146,23 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
11461146

11471147
#if UNIFIED_NETCODE
11481148
// TODO-UNIFIED: This is a temporary POC fix to handle synchronizing hybrid spawned objects where the Ghost instance might not yet exist.
1149-
if (sceneObject.HasGhost && !networkManager.SpawnManager.GhostsPendingSpawn.ContainsKey(sceneObject.NetworkObjectId))
1149+
if (serializedObject.HasGhost && !networkManager.SpawnManager.GhostsPendingSpawn.ContainsKey(serializedObject.NetworkObjectId))
11501150
{
11511151
if (networkManager.LogLevel == LogLevel.Developer)
11521152
{
1153-
UnityEngine.Debug.Log($"[{nameof(SceneEventData)}][{nameof(SynchronizeSceneNetworkObjects)}] Deferring creation of NetworkObjectId-{sceneObject.NetworkObjectId} to wait for Ghost.");
1153+
UnityEngine.Debug.Log($"[{nameof(SceneEventData)}][{nameof(SynchronizeSceneNetworkObjects)}] Deferring creation of NetworkObjectId-{serializedObject.NetworkObjectId} to wait for Ghost.");
11541154
}
11551155

11561156
var newEntry = new PendingGhostSpawnEntry()
11571157
{
11581158
RegistrationTime = UnityEngine.Time.realtimeSinceStartup,
1159-
SceneObject = sceneObject,
1160-
Buffer = new FastBufferReader(InternalBuffer, Allocator.Persistent, sceneObject.SynchronizationDataSize)
1159+
SerializedObject = serializedObject,
1160+
Buffer = new FastBufferReader(InternalBuffer, Allocator.Persistent, serializedObject.SynchronizationDataSize)
11611161
};
11621162

11631163
spawnManager.RegisterGhostPendingSynchronization(newEntry);
11641164

1165-
InternalBuffer.Seek(InternalBuffer.Position + sceneObject.SynchronizationDataSize);
1165+
InternalBuffer.Seek(InternalBuffer.Position + serializedObject.SynchronizationDataSize);
11661166
continue;
11671167
}
11681168
#endif
@@ -1459,7 +1459,7 @@ internal struct PendingGhostSpawnEntry
14591459
{
14601460
public float RegistrationTime;
14611461
public FastBufferReader Buffer;
1462-
public NetworkObject.SceneObject SceneObject;
1462+
public NetworkObject.SerializedObject SerializedObject;
14631463

14641464
}
14651465
#endif

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal NetworkObject GetGhostNetworkObjectForSpawn(ulong networkObjectId)
6565
internal readonly Dictionary<ulong, PendingGhostSpawnEntry> GhostsPendingSynchronization = new Dictionary<ulong, PendingGhostSpawnEntry>();
6666
internal void RegisterGhostPendingSynchronization(PendingGhostSpawnEntry pendingGhostSpawnEntry)
6767
{
68-
var networkObjectId = pendingGhostSpawnEntry.SceneObject.NetworkObjectId;
68+
var networkObjectId = pendingGhostSpawnEntry.SerializedObject.NetworkObjectId;
6969
if (NetworkManager.LogLevel == LogLevel.Developer)
7070
{
7171
Debug.Log($"[{nameof(RegisterGhostPendingSpawn)}] Registering {nameof(NetworkObject)}-{networkObjectId} for pending synchronization.");
@@ -77,20 +77,20 @@ internal void RegisterGhostPendingSynchronization(PendingGhostSpawnEntry pending
7777
internal void ProcessGhostPendingSynchronization(ulong networkObjectId, bool removeUponSpawn = true)
7878
{
7979
var ghostPendingSynch = GhostsPendingSynchronization[networkObjectId];
80-
var sceneObject = ghostPendingSynch.SceneObject;
80+
var serializedObject = ghostPendingSynch.SerializedObject;
8181
var reader = ghostPendingSynch.Buffer;
8282
if (removeUponSpawn)
8383
{
8484
GhostsPendingSynchronization.Remove(networkObjectId);
8585
}
8686

87-
if (sceneObject.IsSceneObject)
87+
if (serializedObject.IsSceneObject)
8888
{
89-
NetworkManager.SceneManager.SetTheSceneBeingSynchronized(sceneObject.NetworkSceneHandle);
89+
NetworkManager.SceneManager.SetTheSceneBeingSynchronized(serializedObject.NetworkSceneHandle);
9090
}
91-
var networkObject = NetworkObject.AddSceneObject(sceneObject, reader, NetworkManager);
91+
var networkObject = NetworkObject.Deserialize(serializedObject, reader, NetworkManager);
9292
// TODO-UNIFIED: How do we handle the "all in-scene placed objects are spawned notification"?
93-
//if (sceneObject.IsSceneObject)
93+
//if (serializedObject.IsSceneObject)
9494
//{
9595
// networkObject.InternalInSceneNetworkObjectsSpawned();
9696
//}
@@ -115,11 +115,11 @@ internal void ProcessAllGhostsPendingSynchronization()
115115
}
116116
foreach (var ghost in GhostsPendingSynchronization)
117117
{
118-
var networkObjectId = ghost.Value.SceneObject.NetworkObjectId;
118+
var networkObjectId = ghost.Value.SerializedObject.NetworkObjectId;
119119
if (GhostsPendingSpawn.ContainsKey(networkObjectId))
120120
{
121121
// Process it, but don't remove it as we handle that a little later
122-
ProcessGhostPendingSynchronization(ghost.Value.SceneObject.NetworkObjectId, false);
122+
ProcessGhostPendingSynchronization(ghost.Value.SerializedObject.NetworkObjectId, false);
123123
m_GhostSynchronizationPendingRemoval.Add(networkObjectId);
124124
}
125125
else
@@ -134,7 +134,7 @@ internal void ProcessAllGhostsPendingSynchronization()
134134
}
135135
}
136136

137-
foreach(var networkObjectId in m_GhostSynchronizationPendingRemoval)
137+
foreach (var networkObjectId in m_GhostSynchronizationPendingRemoval)
138138
{
139139
var entry = GhostsPendingSynchronization[networkObjectId];
140140
GhostsPendingSynchronization.Remove(networkObjectId);
@@ -1025,30 +1025,30 @@ internal NetworkObject CreateLocalNetworkObject(NetworkObject.SerializedObject s
10251025
var worldPositionStays = (!serializedObject.HasParent) || serializedObject.WorldPositionStays;
10261026

10271027
#if UNIFIED_NETCODE
1028-
if (sceneObject.HasGhost)
1028+
if (serializedObject.HasGhost)
10291029
{
10301030
// TODO-UNIFIED: Get this working somehow (or if not possible prevent this from happening prior to getting to this point)
1031-
if (sceneObject.HasInstantiationData)
1031+
if (serializedObject.HasInstantiationData)
10321032
{
10331033
Debug.LogError($"[{nameof(NetworkObject)}] Pre-spawn instantiation data does not work in this version!");
10341034
}
1035-
networkObject = GetGhostNetworkObjectForSpawn(sceneObject.NetworkObjectId);
1035+
networkObject = GetGhostNetworkObjectForSpawn(serializedObject.NetworkObjectId);
10361036
if (networkObject == null)
10371037
{
1038-
throw new Exception($"[{name}] Failed to get spawned Ghost object!");
1038+
throw new Exception($"Failed to get spawned Ghost object!");
10391039
}
10401040
}
10411041
else
10421042
#endif
10431043
{
10441044
// If scene management is disabled or the NetworkObject was dynamically spawned
1045-
if (!NetworkManager.NetworkConfig.EnableSceneManagement || !sceneObject.IsSceneObject)
1045+
if (!NetworkManager.NetworkConfig.EnableSceneManagement || !serializedObject.IsSceneObject)
10461046
{
1047-
networkObject = GetNetworkObjectToSpawn(sceneObject.Hash, sceneObject.OwnerClientId, position, rotation, sceneObject.IsSceneObject, instantiationData);
1047+
networkObject = GetNetworkObjectToSpawn(serializedObject.Hash, serializedObject.OwnerClientId, position, rotation, serializedObject.IsSceneObject, instantiationData);
10481048
}
10491049
else // Get the in-scene placed NetworkObject
10501050
{
1051-
networkObject = NetworkManager.SceneManager.GetSceneRelativeInSceneNetworkObject(globalObjectIdHash, sceneObject.NetworkSceneHandle);
1051+
networkObject = NetworkManager.SceneManager.GetSceneRelativeInSceneNetworkObject(globalObjectIdHash, serializedObject.NetworkSceneHandle);
10521052
if (networkObject == null)
10531053
{
10541054
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)

0 commit comments

Comments
 (0)