Update the text within a MeshResource.generateText

How do I change the text of a MeshResource.generateText after I have created it and added it to an anchor?
Answered by DTS Engineer in 624031022
Hello,

You will need to replace the MeshResource (which had the old text) of the ModelComponent of your entity with a MeshResource that has the new text.

For example:

Code Block
let originalTextMesh = MeshResource.generateText("Hello", extrusionDepth: 0.01, font: .systemFont(ofSize: 0.1))
        let entity = ModelEntity(mesh: originalTextMesh)
let newTextMesh = MeshResource.generateText("World", extrusionDepth: 0.01, font: .systemFont(ofSize: 0.1))
        entity.model?.mesh = newTextMesh


Accepted Answer
Hello,

You will need to replace the MeshResource (which had the old text) of the ModelComponent of your entity with a MeshResource that has the new text.

For example:

Code Block
let originalTextMesh = MeshResource.generateText("Hello", extrusionDepth: 0.01, font: .systemFont(ofSize: 0.1))
        let entity = ModelEntity(mesh: originalTextMesh)
let newTextMesh = MeshResource.generateText("World", extrusionDepth: 0.01, font: .systemFont(ofSize: 0.1))
        entity.model?.mesh = newTextMesh


Update the text within a MeshResource.generateText
 
 
Q