question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException on USD export

See original GitHub issue

I was attempting to export the blacksmith environment (Bridge_small_02 scene):

https://assetstore.unity.com/packages/essentials/asset-packs/the-blacksmith-environments-39948

…and got a NullReferenceException:

NullReferenceException: Object reference not set to an instance of an object
Unity.Formats.USD.MeshExporter.ExportMesh (Unity.Formats.USD.ObjectContext objContext, Unity.Formats.USD.ExportContext exportContext, UnityEngine.Mesh mesh, UnityEngine.Material sharedMaterial, UnityEngine.Material[] sharedMaterials, System.Boolean exportMeshPose) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/MeshExporter.cs:162)
Unity.Formats.USD.MeshExporter.ExportMesh (Unity.Formats.USD.ObjectContext objContext, Unity.Formats.USD.ExportContext exportContext) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/MeshExporter.cs:147)
Unity.Formats.USD.SceneExporter.ExportImpl (UnityEngine.GameObject root, Unity.Formats.USD.ExportContext context) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneExporter.cs:220)
Unity.Formats.USD.SceneExporter.Export (UnityEngine.GameObject root, Unity.Formats.USD.ExportContext context, System.Boolean zeroRootTransform) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneExporter.cs:158)
Unity.Formats.USD.SceneExporter.Export (UnityEngine.GameObject root, USD.NET.Scene scene, Unity.Formats.USD.BasisTransformation basisTransform, System.Boolean exportUnvarying, System.Boolean zeroRootTransform, System.Boolean exportMaterials, System.Boolean exportMonoBehaviours) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneExporter.cs:128)
Unity.Formats.USD.UsdMenu.ExportSelected (Unity.Formats.USD.BasisTransformation basisTransform, System.String fileExtension, System.Boolean exportMonoBehaviours) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs:180)
UnityEngine.Debug:LogException(Exception)
Unity.Formats.USD.UsdMenu:ExportSelected(BasisTransformation, String, Boolean) (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs:184)
Unity.Formats.USD.UsdMenu:MenuExportSelectedWithChildren() (at D:/Storage/3D/Unity/usd-unity-sdk-1.0.0-preview.4/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs:67)

I got the error when attempting to export the top-level “Environment” object in the hierarchy. I’m sure it’s erroring because there’s some entities that it can’t export properly (I don’t expect it to work on everything!), but it would be nice if it could perhaps print an error, and then continue on with exporting what it can. While it does indeed create a USD export, it seems to only contain what it traversed before the error - in my case, it only had Environment/Ferns, and, ie, nothing from Environment/Boardwalks, or anything else.

unity-sdk-1.0.0-preview.4 release OS: Windows 10 Unity: 2019.1.0b8

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pmolodocommented, Mar 22, 2019

Hmm, which bug are you referring to? I actually just made a PR so USD can deal with TIF / JPG / etc (instead of just tif/jpg), is that what you’re referring to?

Anyway, that looks good, I’m going to close this issue! And thanks for this great plugin - other than this one small issue, it was amazingly simple and easy to use!

1reaction
pmolodocommented, Mar 19, 2019

Took a look at MeshExporter.cs, and it looks like the check for mesh == null just needs to be moved up, before the check for mesh.isReadable

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a Null Reference Exception?
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable ...
Read more >
What is a Null Reference Exception?
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable ...
Read more >
Changes in usd-unitysdk for Unity | USD | 1.0.3-preview.2
Bug fixes : NullReferenceException on USD export (#67); Path of .usd file does not match textures in the archive (#88); Build error when...
Read more >
Null Exception while exporting
Problem. When the columns bound to the Grid are not defined in the Grid dataSource, and are passed to the exporting method in...
Read more >
When trying to export a USD file with animation enabled I get ...
Because so far the example USD files work fine in Unity, but the Blender exported ones have that problem and I have to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found