Skip to content

Commit b68bac5

Browse files
revert and update
- `ISerializationCallbackReceiver` implementation as that does not accomplish what we need. - Setting InScenePlaced within OnValidate instead.
1 parent 7551a56 commit b68bac5

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,8 @@ namespace Unity.Netcode
2424
[AddComponentMenu("Netcode/Network Object", -99)]
2525
[DisallowMultipleComponent]
2626
[HelpURL(HelpUrls.NetworkObject)]
27-
public sealed class NetworkObject : MonoBehaviour, ISerializationCallbackReceiver
27+
public sealed class NetworkObject : MonoBehaviour
2828
{
29-
void ISerializationCallbackReceiver.OnBeforeSerialize()
30-
{
31-
// If we are playing or it is an invalid GameObject, then exit early.
32-
if (Application.isPlaying || gameObject == null || gameObject.IsDestroying())
33-
{
34-
return;
35-
}
36-
InScenePlaced = gameObject.scene.IsValid() && gameObject.scene.buildIndex >= 0;
37-
}
38-
39-
void ISerializationCallbackReceiver.OnAfterDeserialize()
40-
{
41-
}
42-
4329
[HideInInspector]
4430
[SerializeField]
4531
internal uint GlobalObjectIdHash;
@@ -143,9 +129,6 @@ public uint PrefabIdHash
143129
// The InContext or InIsolation edit mode network prefab scene instance of the prefab asset (s_PrefabAsset).
144130
private static NetworkObject s_PrefabInstance;
145131

146-
private static bool s_DebugPrefabIdGeneration;
147-
148-
149132
[ContextMenu("Refresh In-Scene Prefab Instances")]
150133
internal void RefreshAllPrefabInstances()
151134
{
@@ -342,7 +325,7 @@ internal void OnValidate()
342325
/// </remarks>
343326
private void CheckForInScenePlaced()
344327
{
345-
if (gameObject.scene.IsValid() && gameObject.scene.isLoaded && gameObject.scene.buildIndex >= 0)
328+
if (gameObject.scene.IsValid() && gameObject.scene.buildIndex >= 0)
346329
{
347330
if (PrefabUtility.IsPartOfAnyPrefab(this))
348331
{
@@ -362,7 +345,7 @@ private void CheckForInScenePlaced()
362345
SetSceneObjectStatus(true);
363346
#pragma warning restore CS0618 // Type or member is obsolete
364347

365-
// We go ahead and set this for "typical in-scene placed" usage patterns.
348+
// We go ahead and set this for "typical in-scene placed" usage patterns so this is serialized
366349
InScenePlaced = true;
367350

368351
// Default scene migration synchronization to false for in-scene placed NetworkObjects
@@ -1252,12 +1235,22 @@ public bool HasOwnershipStatus(OwnershipStatus status)
12521235
[Obsolete("Use InScenePlaced instead")]
12531236
public bool? IsSceneObject { get; internal set; }
12541237

1238+
12551239
/// <summary>
1256-
/// True if this object is placed in a scene; false otherwise.
1240+
/// The serialized value.
12571241
/// </summary>
12581242
[field: HideInInspector]
12591243
[field: SerializeField]
1260-
public bool InScenePlaced { get; internal set; }
1244+
private bool m_InScenePlaced;
1245+
1246+
/// <summary>
1247+
/// True if this object is placed in a scene; false otherwise.
1248+
/// </summary>
1249+
public bool InScenePlaced
1250+
{
1251+
get { return m_InScenePlaced; }
1252+
internal set { m_InScenePlaced = value; }
1253+
}
12611254

12621255
/// <summary>
12631256
/// Sets whether this NetworkObject was instantiated as part of a scene

0 commit comments

Comments
 (0)