In code I’m creating an empty GO, adding prefabs and the CombineChildren script. Then I want to use the combined mesh that is created on a Mesh Collider.
Error Message:
MissingComponentException: There is no ‘MeshFilter’ attached to the “terrain1” game object, but a script is trying to access it.
You probably need to add a MeshFilter to the game object “terrain1”. Or your script needs to check if the component is attached before using it.
The mesh object exists. You can see it in the inspector.
While running I can add the combined mesh object to the collider manually in the inspector. This works fine, but need it to work in code.
EditElev is a script that raises and lowers the mesh when its clicked on. Its how I know the collider is working, or not.
// created empty GO terrain1,
//added script CC,
//added prefabs to be children of terrain1
terrain1.active = true; //runs attached scripts like CombineChildren
terrain1.AddComponent(typeof(MeshCollider));
MeshCollider mc = (MeshCollider)terrain1.GetComponent(typeof(MeshCollider));
MeshFilter mf = (MeshFilter)terrain1.GetComponent(typeof(MeshFilter));
mc.sharedMesh = mf.sharedMesh; // <---------bad line--------
terrain1.AddComponent("EditElev");
After some more work, this is happening because the process for making the combined mesh is “probably” seperate from this code and isnt finished before I call for the mesh.
I set the code after the .active command to start on a button click and it worked.
So I need a way to wait for the mesh to be created before I call it. I tried some looping but it was infinite.
I tried putting a yield in it but I get that “expecting ;” error.
Ok, so you think it is that you access the reference before the Combine Children script is finished.
I do know that you can access that combine children script (correct me if im wrong please)
Why dont you modify it and create a flag that let you know when the combine children has done and then activate your trigger based on the flag you created?
I just went for a 15 min walk before your first answer and I was thinking the same thing, adjusting the Combine Children script. Exactly what form that takes I havent figured out yet.
I suspect that I may be doing that main GO with one Update() entry point. So I can register/unregister classes for updates. Having a hundred updates() attached to GOs all doing nothing 99.9% of the time is silly.
We’ll see, I’m still in hacking around learning mode