How to load a mesh from an asset bundle?
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 nor read");
GameObject silverObject = vshojoBundle.LoadAsset("SilverAssets.obj");
MeshFilter silverNewMesh = silverObject.GetComponent();
meshNames.Add(silverNewMesh.mesh.name);
//
MeshNames is 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.
Your answer
Follow this Question
Related Questions
Problem with character meshes in Unity (exported from blender) 2 Answers
How to load a Unity GameObject during runtime? 0 Answers
How do i use lines to calculate triangles on mesh?? 0 Answers
Instantiating without the use of Resource Folder in Unity? 0 Answers
How to make a pyramid-ish shape from a cube in unity (for making a muzzle flash) 1 Answer