Skip to content

Commit edec9c1

Browse files
committed
[Unity plugin] Surface a clear error when mesh asset is missing
When an MJCF references a mesh whose asset failed to import, or whose name collides with another asset of a different type in the Resources folder, Resources.Load<Mesh>(...) returns null. The Mesh field is then dereferenced silently later (in BuildMesh / DebugDraw), producing an opaque NullReferenceException far from the root cause. Throw a descriptive exception at the load site so users hit the import abort path with a message that points at the actual problem. Related to #1354 (typed Resources.Load was already in place; this adds the missing diagnostic on top).
1 parent 5ee8bd7 commit edec9c1

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

unity/Runtime/Components/Shapes/MjMeshShape.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public void FromMjcf(XmlElement mjcf) {
3737
mjcf.GetStringAttribute("mesh", defaultValue: string.Empty));
3838
if (!string.IsNullOrEmpty(assetName)) {
3939
Mesh = Resources.Load<Mesh>(assetName);
40+
if (Mesh == null) {
41+
throw new Exception(
42+
$"Could not load mesh asset '{assetName}'. The MJCF references a mesh "
43+
+ "that was not imported, or another asset of a different type (e.g. a "
44+
+ "material) shares the same name in a Resources folder.");
45+
}
4046
}
4147
}
4248

0 commit comments

Comments
 (0)