- Home /
Question by
bonisthegreat · Jul 19, 2017 at 10:31 AM ·
gameobjectmeshtextmeshaddcomponent
Can't add TextMesh to gameObject
I cant add TextMesh to a cube because it conflicts with the existing MeshFilter, but I have previously destroyed such MeshFilter.
MeshFilter lettersMeshFilter = letterCube.GetComponent<MeshFilter>();
Destroy(lettersMeshFilter);
TextMesh textMesh = letterCube.AddComponent<TextMesh>() as TextMesh;
letterCube is created with no errors and I can set other attributes to it. letterCube is a gameObject, a Cube. Both letterCube and textMesh are created entirely on a script at runtime.
Any ideas?
Thanks in advanced!
Comment
Are you sure this is where you get the null reference? Show us some more of the code?
Yes, If I log text$$anonymous$$esh right after this line shows Null
Edited the question with an update
Best Answer
Answer by bonisthegreat · Jul 19, 2017 at 11:21 AM
Fixed it by changing:
Destroy(lettersMeshFilter);
For:
DestroyImmediate(lettersMeshFilter);
Your answer
