0
\$\begingroup\$

I have a script that creates a quad mesh, saves the mesh as an asset, and assembles a game object based on some parameters. If I add another component to the GameObject after, the mesh is marked "(Clone)".

gif for reference. This all happens in code but results are the same when doing it manually.
Mesh reference is now a (Clone)

-

When I drag the object to the project view to make it a prefab, the Mesh Filter loses it's Mesh reference. It's fine if I manually assign the mesh afterwards but that defeats the purpose of doing it this way. To be clear, if I don't add this (or any) component, it works fine and can be made into a prefab without issue.

\$\endgroup\$
3
  • \$\begingroup\$ Are you actually adjusting the UV data in the mesh? \$\endgroup\$
    – Sidar
    Sep 9 '17 at 17:16
  • \$\begingroup\$ I am actually. I thought I had ruled that out as not being the issue but I was wrong. \$\endgroup\$
    – liam
    Sep 9 '17 at 17:18
  • \$\begingroup\$ If you're just adjusting the uv mapping in the shader it's fine. But once you start messing with the actual vertex buffer, you most likely are making a clone in script to preserve the original. If you adjust the original all instances will be adjusted. \$\endgroup\$
    – Sidar
    Sep 9 '17 at 17:29
0
\$\begingroup\$

It sounds like your UV adjuster script might be accessing

GetComponent<MeshFilter>().mesh

As with renderer.material, accessing this getter creates a local copy of the asset, so any changes you make will be local to this instance and not spill over into other instances using the asset, or your asset source file itself.

If you want to modify the mesh dynamically, this is probably the behaviour you want.

If you want to access the original, uncopied mesh, then you'd use the .sharedMesh getter instead.

\$\endgroup\$
1
  • \$\begingroup\$ This helps explain the problem a lot. I did want to create the new GameObject from the resource but also needed to control each GameObject's UVs dynamically. I simply needed to save the prefab before I made a dynamic copy of the Mesh resource. \$\endgroup\$
    – liam
    Sep 9 '17 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .