1

I'm trying to load a mesh with scripts to replace another mesh. I'm not doing a Unity project but rather a visual studio project with unity references. My code for loading the asset bundle and getting the mesh is:

var vshojoBundle = AssetBundle.LoadFromFile("vshojo");
if (vshojoBundle == null) meshNames.Add("bundle not read");
GameObject silverObject = vshojoBundle.LoadAsset("SilverAssets.obj");
MeshFilter silverNewMesh = silverObject.GetComponent<MeshFilter>();
meshNames.Add(silverNewMesh.mesh.name);

MeshNames is just a list that later gets written in a log file to help me figure out things. When trying to get the name of the mesh in the last line, I get the following error: NullReferenceExpection: System.NullReferenceException: Object reference not set to an instance of an Object. The same exception occurs if I don't use that line to write on log and skip to the mesh replacement, when I replace the mesh I get the same error.

Loll Starr
  • 45
  • 1
  • 7
  • Could you separate it into `var meshFilter = silverObject.GetComponent(); var mesh = meshFilter.mesh;` to see what exactly is returning `null`? – derHugo Apr 14 '21 at 15:42
  • I tried your suggestion, It's the MeshFilter the one that returns null. Same thing happens if I load a Mesh directly ` var silverMeshFilter = silverObject.GetComponent(); ` I even tried MeshRenderer and SkinnedMeshRenderer, but same result. The mesh I'm trying to load is a .obj and it works perfectly fine in 3d viewers and even importing it directly onto an Unity project (which is how I made the bundle in the first place). – Loll Starr Apr 14 '21 at 22:22

0 Answers0