Skip to content
Draft
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
6 changes: 3 additions & 3 deletions Editor/Scripts/GLTFExportMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,14 @@ private static void CreateNewAsset()

var importAction = ScriptableObject.CreateInstance<AdjustImporterAction>();
importAction.fileContent = content;
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, importAction, filename, null, (string) null);
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(EntityId.None, importAction, filename, null, (string) null);
}

// Based on DoCreateAssetWithContent.cs
private class AdjustImporterAction : EndNameEditAction
private class AdjustImporterAction : AssetCreationEndAction
{
public string fileContent;
public override void Action(int instanceId, string pathName, string resourceFile)
public override void Action(EntityId entityId, string pathName, string resourceFile)
{
var templateContent = SetLineEndings(fileContent, EditorSettings.lineEndingsForNewScripts);
File.WriteAllText(Path.GetFullPath(pathName), templateContent);
Expand Down
4 changes: 2 additions & 2 deletions Editor/Scripts/GLTFImporterInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ private void ModelInspectorGUI()
private const string TextureRemappingKey = nameof(GLTFImporterInspector) + "_TextureRemapping";
private bool EnableTextureRemapping
{
get => SessionState.GetBool(TextureRemappingKey + target.GetInstanceID(), false);
set => SessionState.SetBool(TextureRemappingKey + target.GetInstanceID(), value);
get => SessionState.GetBool(TextureRemappingKey + target.GetEntityId().GetHashCode(), false);
set => SessionState.SetBool(TextureRemappingKey + target.GetEntityId().GetHashCode(), value);
}
private static readonly GUIContent RemapTexturesToggleContent = new GUIContent("Experimental", "(experimental) Remap textures inside the glTF to textures that are already in your project.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
int typeIndex = 0;

// using VariableKind.Scene, because we already generated a unique name for the variable
var varIndex = unitExporter.vsExportContext.AddVariableWithIdIfNeeded($"SelectOnFlowValue_{GUID.Generate().ToString()}", null, VariableKind.Scene, typeIndex);
var varIndex = unitExporter.vsExportContext.AddVariableWithIdIfNeeded($"SelectOnFlowValue_{Guid.NewGuid():N}", null, VariableKind.Scene, typeIndex);

var getVar = VariablesHelpers.GetVariable(unitExporter, varIndex, out var getVarValue);
getVarValue.MapToPort(unit.selection);
Expand Down Expand Up @@ -82,4 +82,4 @@ void PostTypeResolving(bool lastTry = false)
return true;
}
}
}
}
6 changes: 3 additions & 3 deletions Editor/Scripts/ShaderGraph/MaterialLibraryEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public void SetMaterial(Material mat)
img.image = preview;
if (!preview)
{
var instanceId = mat.GetInstanceID();
var entityId = mat.GetEntityId();
void WaitForPreview()
{
if (AssetPreview.IsLoadingAssetPreview(instanceId)) return;
if (AssetPreview.IsLoadingAssetPreview(entityId)) return;
EditorApplication.update -= WaitForPreview;
img.image = AssetPreview.GetAssetPreview(mat);
}
Expand Down Expand Up @@ -210,4 +210,4 @@ public override void DrawPreview(Rect previewArea)

public override bool HasPreviewGUI() => true;
}
}
}
17 changes: 14 additions & 3 deletions Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ public override bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot g
private List<GLTFExportPluginContext> _plugins = new List<GLTFExportPluginContext>();

public IReadOnlyList<GLTFExportPluginContext> Plugins => _plugins;

private static int GetExportedObjectKey(UnityEngine.Object obj)
{
return obj ? obj.GetEntityId().GetHashCode() : 0;
}

private static string GetObjectIdLabel(UnityEngine.Object obj)
{
return obj ? obj.GetEntityId().ToString() : "None";
}

public struct TextureMapType
{
Expand Down Expand Up @@ -1086,7 +1096,8 @@ private SceneId ExportScene(string name, Transform[] rootObjTransforms)

private NodeId ExportNode(Transform nodeTransform)
{
if (_exportedTransforms.TryGetValue(nodeTransform.GetInstanceID(), out var existingNodeId))
int transformKey = GetExportedObjectKey(nodeTransform);
if (_exportedTransforms.TryGetValue(transformKey, out var existingNodeId))
return new NodeId() { Id = existingNodeId, Root = _root };

foreach (var plugin in _plugins)
Expand Down Expand Up @@ -1158,7 +1169,7 @@ private NodeId ExportNode(Transform nodeTransform)
};

// Register nodes for animation parsing (could be disabled if animation is disabled)
_exportedTransforms.Add(nodeTransform.GetInstanceID(), _root.Nodes.Count);
_exportedTransforms.Add(transformKey, _root.Nodes.Count);

_root.Nodes.Add(node);

Expand Down Expand Up @@ -1387,7 +1398,7 @@ public MaterialId GetMaterialId(GLTFRoot root, Material materialObj)
if (materialObj == DefaultMaterial)
materialKey = 0;
else if (materialObj)
materialKey = materialObj.GetInstanceID();
materialKey = GetExportedObjectKey(materialObj);

if (_exportedMaterials.TryGetValue(materialKey, out var id))
{
Expand Down
14 changes: 13 additions & 1 deletion Runtime/Scripts/RenderPipelines/RoughRefractionFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RoughRefractionFeature : ScriptableRendererFeature
#if !UNITY_6000_2_OR_NEWER
private Downsampling downsampling = Downsampling.None;
#endif
#if !UNITY_6000_4_OR_NEWER
class CustomRenderPass : CopyColorPass
{
public Downsampling m_DownsamplingMethod;
Expand Down Expand Up @@ -129,8 +130,11 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin
#endif
}
}
#endif

#if !UNITY_6000_4_OR_NEWER
private CustomRenderPass m_RoughRefractionPassNonRG;
#endif
#if UNITY_2023_3_OR_NEWER
private bool usingRenderGraph = false;
#endif
Expand All @@ -143,11 +147,16 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin
public override void Create()
{
#if UNITY_2023_3_OR_NEWER
#if UNITY_6000_4_OR_NEWER
usingRenderGraph = true;
#else
var renderGraphSettings = GraphicsSettings.GetRenderPipelineSettings<RenderGraphSettings>();
usingRenderGraph = !renderGraphSettings.enableRenderCompatibilityMode;
#endif
if (!usingRenderGraph)
{
#endif
#if !UNITY_6000_4_OR_NEWER
#if UNITY_2022_3_OR_NEWER
if (m_RoughRefractionPassNonRG == null)
{
Expand All @@ -156,6 +165,7 @@ public override void Create()
#else
m_OpaqueColor.Init(CAMERA_OPAQUE_TEXTURENAME);
#endif
#endif

#if UNITY_2023_3_OR_NEWER
}
Expand All @@ -178,10 +188,12 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
return;

#if UNITY_2022_3_OR_NEWER
#if !UNITY_6000_4_OR_NEWER
if (m_RoughRefractionPassNonRG != null)
{
renderer.EnqueuePass(m_RoughRefractionPassNonRG);
}
#endif
#if UNITY_2023_3_OR_NEWER
else
if (usingRenderGraph && m_RoughRefractionPassRG != null)
Expand All @@ -206,7 +218,7 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
#endif
}

#if UNITY_2022_3_OR_NEWER && !UNITY_6000_2_OR_NEWER
#if UNITY_2022_3_OR_NEWER && !UNITY_6000_2_OR_NEWER && !UNITY_6000_4_OR_NEWER
public override void SetupRenderPasses(ScriptableRenderer renderer, in RenderingData renderingData)
{
#pragma warning disable 618
Expand Down
12 changes: 6 additions & 6 deletions Runtime/Scripts/SceneExporter/ExporterAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ private static string LogObject(object obj)
if (obj == null) return "null";

if (obj is Component tr)
return $"{tr.name} (InstanceID: {tr.GetInstanceID()}, Type: {tr.GetType()})";
return $"{tr.name} (EntityId: {GetObjectIdLabel(tr)}, Type: {tr.GetType()})";
if (obj is GameObject go)
return $"{go.name} (InstanceID: {go.GetInstanceID()})";
return $"{go.name} (EntityId: {GetObjectIdLabel(go)})";

return obj.ToString();
}
Expand Down Expand Up @@ -1589,25 +1589,25 @@ internal int GetIndex(object obj)

public int GetTransformIndex(Transform transform)
{
if (transform && _exportedTransforms.TryGetValue(transform.GetInstanceID(), out var index)) return index;
if (transform && _exportedTransforms.TryGetValue(GetExportedObjectKey(transform), out var index)) return index;
return -1;
}

public int GetMaterialIndex(Material mat)
{
if (mat && _exportedMaterials.TryGetValue(mat.GetInstanceID(), out var index)) return index;
if (mat && _exportedMaterials.TryGetValue(GetExportedObjectKey(mat), out var index)) return index;
return -1;
}

public int GetLightIndex(Light light)
{
if (light && _exportedLights.TryGetValue(light.GetInstanceID(), out var index)) return index;
if (light && _exportedLights.TryGetValue(GetExportedObjectKey(light), out var index)) return index;
return -1;
}

public int GetCameraIndex(Camera cam)
{
if (cam && _exportedCameras.TryGetValue(cam.GetInstanceID(), out var index)) return index;
if (cam && _exportedCameras.TryGetValue(GetExportedObjectKey(cam), out var index)) return index;
return -1;
}

Expand Down
6 changes: 3 additions & 3 deletions Runtime/Scripts/SceneExporter/ExporterAnimationPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public void AddAnimationData(Object animatedObject, string propertyName, GLTFAni
{
if (go.CompareTag("EditorOnly"))
{
Debug.LogWarning(null, $"Animation for {animatedObject.name} ({animatedObject.GetType()}) has not been exported as the object itself is not exported (EditorOnly). Remove the EditorOnly tag when you want to export the GameObject. (InstanceID: {animatedObject.GetInstanceID()})", animatedObject);
Debug.LogWarning(null, $"Animation for {animatedObject.name} ({animatedObject.GetType()}) has not been exported as the object itself is not exported (EditorOnly). Remove the EditorOnly tag when you want to export the GameObject. (EntityId: {GetObjectIdLabel(animatedObject)})", animatedObject);
return;
}
if (!go.activeSelf || !go.activeInHierarchy)
{
Debug.LogWarning(null, $"Animation for {animatedObject.name} ({animatedObject.GetType()}) has not been exported as the object itself is not exported. Enable the GameObject when you want to export it or enable 'Export disabled Game Objects' in the settings. (InstanceID: {animatedObject.GetInstanceID()})", animatedObject);
Debug.LogWarning(null, $"Animation for {animatedObject.name} ({animatedObject.GetType()}) has not been exported as the object itself is not exported. Enable the GameObject when you want to export it or enable 'Export disabled Game Objects' in the settings. (EntityId: {GetObjectIdLabel(animatedObject)})", animatedObject);
return;
}

}
Debug.LogWarning(null, $"Animation for {animatedObject.name} ({animatedObject.GetType()}) has not been exported as the object itself is not exported (disabled/EditorOnly). (InstanceID: {animatedObject.GetInstanceID()})", animatedObject);
Debug.LogWarning(null, $"Animation for {animatedObject.name} ({animatedObject.GetType()}) has not been exported as the object itself is not exported (disabled/EditorOnly). (EntityId: {GetObjectIdLabel(animatedObject)})", animatedObject);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneExporter/ExporterCameras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private CameraId ExportCamera(Camera unityCamera)
};

// Register nodes for animation parsing (could be disabled if animation is disabled)
_exportedCameras.Add(unityCamera.GetInstanceID(), _root.Cameras.Count);
_exportedCameras.Add(GetExportedObjectKey(unityCamera), _root.Cameras.Count);
_root.Cameras.Add(camera);

return id;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneExporter/ExporterLights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private LightId ExportLight(Light unityLight)
};

// Register nodes for animation parsing (could be disabled if animation is disabled)
_exportedLights.Add(unityLight.GetInstanceID(), _root.Lights.Count);
_exportedLights.Add(GetExportedObjectKey(unityLight), _root.Lights.Count);

//list of lightids should be in extensions object
_root.Lights.Add(light);
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneExporter/ExporterMaterials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public MaterialId ExportMaterial(Material materialObj)

private MaterialId CreateAndAddMaterialId(Material materialObj, GLTFMaterial material)
{
var key = materialObj ? materialObj.GetInstanceID() : 0;
var key = materialObj ? GetExportedObjectKey(materialObj) : 0;
if(!_exportedMaterials.ContainsKey(key))
_exportedMaterials.Add(key, _root.Materials.Count);

Expand Down
6 changes: 3 additions & 3 deletions Runtime/Scripts/SceneExporter/ExporterSkinning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void ExportSkinFromNode(Transform transform)
Debug.LogWarning("Skin has null bone at index " + i + ": " + skin, skin);
continue;
}
var nodeId = skin.bones[i].GetInstanceID();
var nodeId = GetExportedObjectKey(skin.bones[i]);
if (!_exportedTransforms.ContainsKey(nodeId))
{
allBoneTransformNodesHaveBeenExported = false;
Expand All @@ -66,7 +66,7 @@ private void ExportSkinFromNode(Transform transform)
continue;
}

var nodeId = skin.bones[i].GetInstanceID();
var nodeId = GetExportedObjectKey(skin.bones[i]);

gltfSkin.Joints.Add(
new NodeId
Expand Down Expand Up @@ -130,7 +130,7 @@ private void ExportSkinFromNode(Transform transform)
}
}

_root.Nodes[_exportedTransforms[transform.GetInstanceID()]].Skin = new SkinId() { Id = _root.Skins.Count, Root = _root };
_root.Nodes[_exportedTransforms[GetExportedObjectKey(transform)]].Skin = new SkinId() { Id = _root.Skins.Count, Root = _root };
_root.Skins.Add(gltfSkin);

exportSkinFromNodeMarker.End();
Expand Down
32 changes: 32 additions & 0 deletions UNITY_6_6_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Unity 6.6 viability notes

This branch is not presented as a finished Unity 6.6 support release. It is a record of the changes we used in a consumer project to get UnityGLTF working again on Unity 6.6 alpha.

## What this fixes

- Replaces exporter-side `GetInstanceID()` usage that turns into hard failures on Unity 6.6 with `GetEntityId()`-based keys and labels.
- Updates editor asset creation code to the newer `AssetCreationEndAction` and `EntityId` APIs.
- Updates editor state and preview tracking code to use entity ids where Unity 6.6 no longer accepts instance ids.
- Forces the rough refraction renderer feature onto the RenderGraph-compatible path on newer Unity 6 releases where the older compatibility path is no longer viable.
- Replaces one Visual Scripting exporter `GUID.Generate()` call with `Guid.NewGuid()` to avoid an editor-side API mismatch we hit during the migration.

## Where this was exercised

These changes were taken from a Unity 6.6 alpha migration branch in a real game project that embeds UnityGLTF as a package dependency.

In that consumer project, this patch set was enough to:

- restore clean compilation under Unity 6.6 alpha,
- bring back editor import of existing `.glb` assets that had stopped working after the engine upgrade,
- keep the project's current PlayMode suite green, and
- produce a successful player build again once the surrounding project-side issues were handled.

## Scope and limits

- This branch is intentionally narrow. It captures the concrete changes we needed for Unity 6.6 viability, not a broad compatibility audit across all UnityGLTF features.
- The validation evidence comes from the consumer project integration described above. We did not run a separate full UnityGLTF package test pass in this forked workspace.
- We left out unrelated package metadata and Unity-authored serialization noise from the consumer branch so the patch stays focused on the actual compatibility edits.

## Suggested PR framing

If this goes upstream, the safest framing is: here are the changes we used to get UnityGLTF working for Unity 6.6 in a real project, with the expectation that Khronos can review, tighten, or extend them as needed.