Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Mesh with procedurally generated vertices not rendering in a prefab -- why!?

Discussion in 'Prefabs' started by vittorioromeo, Mar 14, 2023.

  1. vittorioromeo

    vittorioromeo

    Joined:
    Mar 12, 2023
    Posts:
    2
    I *really* need some help understanding why my mesh with procedurally generated vertices doesn't work in prefabs. I have this setup:

    - GameObject
    - TextMeshPro
    - Quad


    The GameObject has my script
    TextWithBackgroundController
    , which holds a reference to the TextMeshPro and the Quad. In its `Update`, it changes the Quad's vertices via
    quad.GetComponent<MeshFilter>().mesh.vertices
    in order to create a background for the TextMeshPro. This works perfectly in both play and edit mode.

    Now, I'd like to make a prefab out of these three objects. When I do so, and spawn a new instance of that prefab, the mesh doesn't render at all. The debugger shows that the vertices are set correctly, but that there are no triangles.
    I can fix the issue by manually going into the new Quad, and changing the mesh from "Quad" to "Quad Instance" in the mesh filter component.

    I don't get it at all. Why does the prefab not render? Why does the mesh not get saved in the prefab? Why does changing the mesh manually fix the issue?

    The source code for my script is here: https://gist.github.com/vittorioromeo/d500c347465f5cc3555001d00a1dd6cc

    Here's a video showcasing the issue:
    https://i.imgur.com/DLPpNJD.mp4

    This is really driving me nuts, I don't understand this behavior at all.
     
  2. vittorioromeo

    vittorioromeo

    Joined:
    Mar 12, 2023
    Posts:
    2