Skip to content

Commit e843f64

Browse files
DaxodeEvergreen
authored andcommitted
InstanceIDToObject -> EntityIdToObject
1 parent 84f49cf commit e843f64

File tree

17 files changed

+64
-55
lines changed

17 files changed

+64
-55
lines changed

Packages/com.unity.render-pipelines.core/Editor/LookDev/Context.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEngine;
33
using System.Collections.Generic;
44
using System.Collections;
5+
using UnityEngine.Serialization;
56

67
namespace UnityEditor.Rendering.LookDev
78
{
@@ -334,16 +335,17 @@ public class ViewContext
334335
// Careful here: we want to keep it while reloading script.
335336
// But from one unity editor to an other, ID are not kept.
336337
// So, only use it when reloading from script update.
338+
[FormerlySerializedAs("viewedObjecHierarchytInstanceID")]
337339
[SerializeField]
338-
int viewedObjecHierarchytInstanceID;
340+
EntityId viewedObjecHierarchytEntityId;
339341

340342
/// <summary>
341343
/// Check if an Environment is registered for this view.
342344
/// The result will be accurate even if the object have not been reloaded yet.
343345
/// </summary>
344346
public bool hasViewedObject =>
345347
!String.IsNullOrEmpty(viewedObjectAssetGUID)
346-
|| viewedObjecHierarchytInstanceID != 0;
348+
|| viewedObjecHierarchytEntityId != 0;
347349

348350
/// <summary>Reference to the object given for instantiation.</summary>
349351
public GameObject viewedObjectReference { get; private set; }
@@ -426,14 +428,14 @@ void LoadEnvironmentFromGUID()
426428
public void UpdateViewedObject(GameObject viewedObject)
427429
{
428430
viewedObjectAssetGUID = "";
429-
viewedObjecHierarchytInstanceID = 0;
431+
viewedObjecHierarchytEntityId = 0;
430432
viewedObjectReference = null;
431433
if (viewedObject == null || viewedObject.Equals(null))
432434
return;
433435

434436
bool fromHierarchy = viewedObject.scene.IsValid();
435437
if (fromHierarchy)
436-
viewedObjecHierarchytInstanceID = viewedObject.GetInstanceID();
438+
viewedObjecHierarchytEntityId = viewedObject.GetInstanceID();
437439
else
438440
viewedObjectAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(viewedObject));
439441
viewedObjectReference = viewedObject;
@@ -451,9 +453,9 @@ void LoadViewedObject()
451453
string path = AssetDatabase.GUIDToAssetPath(viewedObjectAssetGUID);
452454
viewedObjectReference = AssetDatabase.LoadAssetAtPath<GameObject>(path);
453455
}
454-
else if (viewedObjecHierarchytInstanceID != 0)
456+
else if (viewedObjecHierarchytEntityId != 0)
455457
{
456-
viewedObjectReference = EditorUtility.InstanceIDToObject(viewedObjecHierarchytInstanceID) as GameObject;
458+
viewedObjectReference = EditorUtility.EntityIdToObject(viewedObjecHierarchytEntityId) as GameObject;
457459
}
458460
}
459461

@@ -466,7 +468,7 @@ internal void LoadAll(bool reloadWithTemporaryID)
466468
}
467469

468470
internal void CleanTemporaryObjectIndexes()
469-
=> viewedObjecHierarchytInstanceID = 0;
471+
=> viewedObjecHierarchytEntityId = 0;
470472

471473
/// <summary>Reset the camera state to default values</summary>
472474
public void ResetCameraState()

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeBakingSetWeakReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public void Set(ProbeVolumeBakingSet bakingSet)
3636
// Get the referenced baking set, loading it into memory if necessary.
3737
public ProbeVolumeBakingSet Get()
3838
{
39-
return Resources.InstanceIDToObject(m_InstanceID) as ProbeVolumeBakingSet;
39+
return Resources.EntityIdToObject(m_InstanceID) as ProbeVolumeBakingSet;
4040
}
4141

4242
// Is the referenced baking set in memory?
4343
public bool IsLoaded()
4444
{
45-
return Resources.InstanceIDIsValid(m_InstanceID);
45+
return Resources.EntityIdIsValid(m_InstanceID);
4646
}
4747

4848
// Force the referenced baking set to be unloaded from memory.

Packages/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct HDProbeBakingState
2323
public struct ProbeBakingHash : CoreUnsafeUtils.IKeyGetter<HDProbeBakingState, Hash128>
2424
{ public Hash128 Get(ref HDProbeBakingState v) { return v.probeBakingHash; } }
2525

26-
public int instanceID;
26+
public EntityId entityId;
2727
public Hash128 probeBakingHash;
2828
public Hash128 probeBakingHashNoBounce;
2929
}
@@ -33,7 +33,7 @@ struct HDProbeBakedState
3333
public struct ProbeBakedHash : CoreUnsafeUtils.IKeyGetter<HDProbeBakedState, Hash128>
3434
{ public Hash128 Get(ref HDProbeBakedState v) { return v.probeBakedHash; } }
3535

36-
public int instanceID;
36+
public EntityId entityId;
3737
public Hash128 probeBakedHash;
3838
}
3939

@@ -157,8 +157,8 @@ IScriptableBakedReflectionSystemStageNotifier handle
157157
// Force to rebake probe with missing baked texture
158158
for (var i = 0; i < bakedProbeCount; ++i)
159159
{
160-
var instanceId = states[i].instanceID;
161-
var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId);
160+
var entityId = states[i].entityId;
161+
var probe = (HDProbe)EditorUtility.EntityIdToObject(entityId);
162162

163163
if (probe.IsTurnedOff())
164164
continue;
@@ -256,8 +256,8 @@ IScriptableBakedReflectionSystemStageNotifier handle
256256
);
257257

258258
var index = toBakeIndicesList.GetUnchecked(i);
259-
var instanceId = states[index].instanceID;
260-
var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId);
259+
var entityId = states[index].entityId;
260+
var probe = (HDProbe)EditorUtility.EntityIdToObject(entityId);
261261

262262
if(probe.IsTurnedOff())
263263
continue;
@@ -289,8 +289,8 @@ IScriptableBakedReflectionSystemStageNotifier handle
289289
for (int i = 0; i < toBakeIndicesList.Count; ++i)
290290
{
291291
var index = toBakeIndicesList.GetUnchecked(i);
292-
var instanceId = states[index].instanceID;
293-
var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId);
292+
var entityId = states[index].entityId;
293+
var probe = (HDProbe)EditorUtility.EntityIdToObject(entityId);
294294

295295
if (probe.IsTurnedOff())
296296
continue;
@@ -322,8 +322,8 @@ IScriptableBakedReflectionSystemStageNotifier handle
322322
for (int i = 0; i < bakedProbeCount; ++i)
323323
{
324324
var index = toBakeIndicesList.GetUnchecked(i);
325-
var instanceId = states[index].instanceID;
326-
var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId);
325+
var entityId = states[index].entityId;
326+
var probe = (HDProbe)EditorUtility.EntityIdToObject(entityId);
327327
if (string.IsNullOrEmpty(probe.gameObject.scene.path))
328328
continue;
329329

@@ -338,8 +338,8 @@ IScriptableBakedReflectionSystemStageNotifier handle
338338
for (int i = 0; i < toBakeIndicesList.Count; ++i)
339339
{
340340
var index = toBakeIndicesList.GetUnchecked(i);
341-
var instanceId = states[index].instanceID;
342-
var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId);
341+
var entityId = states[index].entityId;
342+
var probe = (HDProbe)EditorUtility.EntityIdToObject(entityId);
343343
if (string.IsNullOrEmpty(probe.gameObject.scene.path))
344344
continue;
345345

@@ -375,7 +375,7 @@ IScriptableBakedReflectionSystemStageNotifier handle
375375
Assert.IsTrue(targetI < targetSize);
376376
targetBakedStates[targetI++] = new HDProbeBakedState
377377
{
378-
instanceID = state.instanceID,
378+
entityId = state.entityId,
379379
probeBakedHash = state.probeBakingHash
380380
};
381381
}
@@ -817,7 +817,7 @@ static void ComputeProbeInstanceID(IEnumerable<HDProbe> probes, HDProbeBakingSta
817817
var i = 0;
818818
foreach (var probe in probes)
819819
{
820-
states[i].instanceID = probe.GetInstanceID();
820+
states[i].entityId = probe.GetInstanceID();
821821
++i;
822822
}
823823
}

Packages/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,15 +1847,15 @@ public void OnAfterDeserialize()
18471847
#if UNITY_EDITOR
18481848
if (k_AssetPreviousVersion != k_AssetVersion)
18491849
{
1850-
EditorApplication.delayCall += () => UpgradeAsset(this.GetInstanceID());
1850+
EditorApplication.delayCall += () => UpgradeAsset(this.GetEntityId());
18511851
}
18521852
#endif
18531853
}
18541854

18551855
#if UNITY_EDITOR
1856-
static void UpgradeAsset(int assetInstanceID)
1856+
static void UpgradeAsset(EntityId assetInstanceID)
18571857
{
1858-
UniversalRenderPipelineAsset asset = EditorUtility.InstanceIDToObject(assetInstanceID) as UniversalRenderPipelineAsset;
1858+
UniversalRenderPipelineAsset asset = EditorUtility.EntityIdToObject(assetInstanceID) as UniversalRenderPipelineAsset;
18591859

18601860
if (asset.k_AssetPreviousVersion < 5)
18611861
{

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineGlobalSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ partial class UniversalRenderPipelineGlobalSettings : RenderPipelineGlobalSettin
3636
#pragma warning restore CS0414
3737

3838
#if UNITY_EDITOR
39-
public static void UpgradeAsset(int assetInstanceID)
39+
public static void UpgradeAsset(EntityId assetInstanceID)
4040
{
41-
if (EditorUtility.InstanceIDToObject(assetInstanceID) is not UniversalRenderPipelineGlobalSettings asset)
41+
if (EditorUtility.EntityIdToObject(assetInstanceID) is not UniversalRenderPipelineGlobalSettings asset)
4242
return;
4343

4444
int assetVersionBeforeUpgrade = asset.m_AssetVersion;
@@ -244,7 +244,7 @@ internal static UniversalRenderPipelineGlobalSettings Ensure(bool canCreateNewAs
244244
{
245245
if (currentInstance != null && !currentInstance.IsAtLastVersion())
246246
{
247-
UpgradeAsset(currentInstance.GetInstanceID());
247+
UpgradeAsset(currentInstance.GetEntityId());
248248
AssetDatabase.SaveAssetIfDirty(currentInstance);
249249
}
250250

Packages/com.unity.render-pipelines.universal/Tests/Editor/URPGlobalSettingsMigrationTests/URPMigrationTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected void DoTest(IGlobalSettingsMigrationTestCase testCase)
7575

7676
testCase.SetUp(m_Instance, m_Asset);
7777

78-
UniversalRenderPipelineGlobalSettings.UpgradeAsset(m_Instance.GetInstanceID());
78+
UniversalRenderPipelineGlobalSettings.UpgradeAsset(m_Instance.GetEntityId());
7979
bool migrationIsPerformed = m_Instance.m_AssetVersion == UniversalRenderPipelineGlobalSettings.k_LastVersion;
8080
bool migrationIsCorrect = false;
8181
string errorMessage = string.Empty;
@@ -100,7 +100,7 @@ protected void DoTest(IRenderPipelineGraphicsSettingsTestCase<TRenderPipelineGra
100100

101101
testCase.SetUp(m_Instance, m_Asset);
102102

103-
UniversalRenderPipelineGlobalSettings.UpgradeAsset(m_Instance.GetInstanceID());
103+
UniversalRenderPipelineGlobalSettings.UpgradeAsset(m_Instance.GetEntityId());
104104
bool migrationIsPerformed = m_Instance.m_AssetVersion == UniversalRenderPipelineGlobalSettings.k_LastVersion;
105105
bool migrationIsCorrect = false;
106106
string errorMessage = string.Empty;

Packages/com.unity.shadergraph/Editor/Generation/Processors/PropertyCollector.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PropertyCollector
1212
public struct TextureInfo
1313
{
1414
public string name;
15-
public int textureId;
15+
public EntityId textureId;
1616
public TextureDimension dimension;
1717
public bool modifiable;
1818
}
@@ -266,7 +266,7 @@ public List<TextureInfo> GetConfiguredTextures()
266266
var textureInfo = new TextureInfo
267267
{
268268
name = prop.referenceName,
269-
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
269+
textureId = prop.value.texture != null ? prop.value.texture.GetEntityId() : EntityId.None,
270270
dimension = TextureDimension.Tex2D,
271271
modifiable = prop.modifiable
272272
};
@@ -281,7 +281,7 @@ public List<TextureInfo> GetConfiguredTextures()
281281
var textureInfo = new TextureInfo
282282
{
283283
name = prop.referenceName,
284-
textureId = prop.value.textureArray != null ? prop.value.textureArray.GetInstanceID() : 0,
284+
textureId = prop.value.textureArray != null ? prop.value.textureArray.GetEntityId() : EntityId.None,
285285
dimension = TextureDimension.Tex2DArray,
286286
modifiable = prop.modifiable
287287
};
@@ -296,7 +296,7 @@ public List<TextureInfo> GetConfiguredTextures()
296296
var textureInfo = new TextureInfo
297297
{
298298
name = prop.referenceName,
299-
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
299+
textureId = prop.value.texture != null ? prop.value.texture.GetEntityId() : EntityId.None,
300300
dimension = TextureDimension.Tex3D,
301301
modifiable = prop.modifiable
302302
};
@@ -311,7 +311,7 @@ public List<TextureInfo> GetConfiguredTextures()
311311
var textureInfo = new TextureInfo
312312
{
313313
name = prop.referenceName,
314-
textureId = prop.value.cubemap != null ? prop.value.cubemap.GetInstanceID() : 0,
314+
textureId = prop.value.cubemap != null ? prop.value.cubemap.GetEntityId() : EntityId.None,
315315
dimension = TextureDimension.Cube,
316316
modifiable = prop.modifiable
317317
};

Packages/com.unity.shadergraph/Editor/Generation/ShaderGraphVfxAsset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal ConcretePrecision concretePrecision
9797

9898
internal void SetTextureInfos(IList<PropertyCollector.TextureInfo> textures)
9999
{
100-
m_TextureInfos = textures.Select(t => new TextureInfo(t.name, EditorUtility.InstanceIDToObject(t.textureId) as Texture, t.dimension)).ToArray();
100+
m_TextureInfos = textures.Select(t => new TextureInfo(t.name, EditorUtility.EntityIdToObject(t.textureId) as Texture, t.dimension)).ToArray();
101101
}
102102

103103
internal void SetOutputs(OutputMetadata[] outputs)

Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ Shader BuildAllShaders(
169169
EditorMaterialUtility.SetShaderDefaults(
170170
shader,
171171
generatedShader.assignedTextures.Where(x => x.modifiable).Select(x => x.name).ToArray(),
172-
generatedShader.assignedTextures.Where(x => x.modifiable).Select(x => EditorUtility.InstanceIDToObject(x.textureId) as Texture).ToArray());
172+
generatedShader.assignedTextures.Where(x => x.modifiable).Select(x => EditorUtility.EntityIdToObject(x.textureId) as Texture).ToArray());
173173

174174
EditorMaterialUtility.SetShaderNonModifiableDefaults(
175175
shader,
176176
generatedShader.assignedTextures.Where(x => !x.modifiable).Select(x => x.name).ToArray(),
177-
generatedShader.assignedTextures.Where(x => !x.modifiable).Select(x => EditorUtility.InstanceIDToObject(x.textureId) as Texture).ToArray());
177+
generatedShader.assignedTextures.Where(x => !x.modifiable).Select(x => EditorUtility.EntityIdToObject(x.textureId) as Texture).ToArray());
178178
}
179179
if (first)
180180
{

Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionAbstractValues.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Runtime.CompilerServices;
4+
using Unity.Collections.LowLevel.Unsafe;
45
using UnityEngine;
56
using UnityEngine.VFX;
67
using UnityObject = UnityEngine.Object;
@@ -272,8 +273,9 @@ public override T Get<T>()
272273
{
273274
if (typeof(T) == typeof(int))
274275
return (T)(object)base.Get();
276+
Debug.Assert(UnsafeUtility.SizeOf<EntityId>() == sizeof(int), "EntityId size is not equal to int size, this will cause issues, update to VFXValue<EntityId> instead");
275277

276-
return (T)(object)EditorUtility.InstanceIDToObject(base.Get());
278+
return (T)(object)EditorUtility.EntityIdToObject(base.Get());
277279
}
278280

279281
public override object GetContent()

0 commit comments

Comments
 (0)