Importing a dynamic object at runtime in Unity.

Hi,

I have been trying to import a dynamic object at run time with unity. This is my scenario : I am designing a ball throw game, and when the user successfully throws a ball at the target, I will make an API call that will return a 3D object and I need to show it to the user. So far, I have tried creating an empty gameobject, and attached a c# script that will import a .obj file from my disc and attach it.

This is the code:

   Mesh holderMesh = new Mesh();
    ObjImporter importer = new ObjImporter();
    holderMesh = importer.ImportFile(@"<path>");
    MeshRenderer renderer = gameObject.AddComponent<MeshRenderer>();
    MeshFilter filter = gameObject.AddComponent<MeshFilter>();
    filter.mesh = holderMesh;

But when running in unity, there is no trace of the object, and when I run in Visual studio, the background turns pink - and in both unity and VS, other static assets are present as usual.

Can you tell me if I am doing something wrong, and what is the best way to return a 3D object with texture info from server that can be easily loaded into unity at runtime?

The easiest way would be to use AssetBundles. They require you to compile them in Unity, but then you can download the whole package dynamically and import the assets within. That way you can change up the content on the server and have your game get new assets seamlessly.

I wouldn’t know what 3D object is returned until the server returns them. They are dynamic. I explored the option of asset bundles but due to this reason I couldn’t go ahead with it. @FortisVenaliter