Skip to content

Commit 6020da6

Browse files
committed
fix: missing prefab data when enter prefab mode
1 parent 3a6b537 commit 6020da6

1 file changed

Lines changed: 7 additions & 27 deletions

File tree

Scripts/GameApi/LiteNetLibIdentity.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ internal static int GetHashedId(string id)
285285
#if UNITY_EDITOR
286286
private void OnValidate()
287287
{
288+
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
289+
if (prefabStage != null && !prefabStage.scene.isLoaded)
290+
{
291+
// In prefab mode, and it is not loaded yet. No data to validate yet, skip it.
292+
return;
293+
}
294+
288295
Event evt = Event.current;
289296
if (evt != null && (string.Equals(evt.commandName, "Duplicate") || string.Equals(evt.commandName, "Paste")))
290297
{
@@ -331,32 +338,15 @@ internal void AssignAssetID(GameObject prefab)
331338

332339
private bool ThisIsAPrefab()
333340
{
334-
#if UNITY_2018_3_OR_NEWER
335341
return PrefabUtility.IsPartOfPrefabAsset(gameObject);
336-
#else
337-
PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);
338-
if (prefabType == PrefabType.Prefab)
339-
return true;
340-
return false;
341-
#endif
342342
}
343343

344344
private bool ThisIsASceneObjectWithThatReferencesPrefabAsset(out GameObject prefab)
345345
{
346346
prefab = null;
347-
#if UNITY_2018_3_OR_NEWER
348347
if (!PrefabUtility.IsPartOfNonAssetPrefabInstance(gameObject))
349348
return false;
350-
#else
351-
PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);
352-
if (prefabType == PrefabType.None)
353-
return false;
354-
#endif
355-
#if UNITY_2018_2_OR_NEWER
356349
prefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
357-
#else
358-
prefab = (GameObject)PrefabUtility.GetPrefabParent(gameObject);
359-
#endif
360350
if (prefab == null)
361351
{
362352
Logging.LogError(LogTag, $"Failed to find prefab parent for scene object: {gameObject.name}.", gameObject);
@@ -387,16 +377,6 @@ internal void AssignAssetID()
387377
if (string.IsNullOrWhiteSpace(sceneObjectId))
388378
Debug.LogWarning($"[LiteNetLibIdentity] No object ID set for {name}", gameObject);
389379
}
390-
else
391-
{
392-
if (Application.isPlaying)
393-
{
394-
Debug.LogWarning($"[LiteNetLibIdentity] Cannot setup IDs while playing", gameObject);
395-
return;
396-
}
397-
// This is a pure scene object (Not a prefab)
398-
assetId = string.Empty;
399-
}
400380
// Do not mark dirty while playing
401381
if (!Application.isPlaying && !string.Equals(oldAssetId, assetId))
402382
EditorUtility.SetDirty(this);

0 commit comments

Comments
 (0)