- Home /
Question by
U3Dev_ · Aug 14, 2016 at 07:26 AM ·
c#gameobjectmesh
Attaching a model to a blank GameObject?
I want to attach a model to an empty GameObject. I have got a code like this:
GameObject factory = new GameObject();
MeshFilter meshFilter = factory.AddComponent<MeshFilter>();
MeshRenderer render = factory.AddComponent<MeshRenderer>();
Mesh mesh = Resources.Load("FactoryModel", typeof(Mesh)) as Mesh;
if (mesh != null)
meshFilter.mesh = mesh;
factory.transform.position = new Vector3(X * 50, 0, Y * 50);
The mesh is loading(checked by printing in log), but game object still shows without any model. Do anybody know what is the problem in my code?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612090757im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mesh.CombineMeshes does not work when mergeSubMeshes=false 2 Answers
How to show 3000+ Trees(generator) without getting Memory overflow (no terrain generator) 0 Answers
Turning off renderer in other game object (C#) 2 Answers
C# Preserving GameObjects' Previous Meshes 1 Answer
Do gameobjects not have a mesh component by default? 2 Answers