- Home /
How can I modify a Mesh object's uv variable directly?
Hello,
I've been experimenting with modifying a Mesh object's uv variable (type: Vector2[]), and I've only been able to make changes to the array via another object:
// Works fine, causes the values in mesh.uv to be changed.
Vector2[] temp = mesh.uv;
DoSomethingToParameter(temp);
mesh.uv = temp;
When I try to modify mesh.uv's elements directly, nothing happens:
DoSomethingToParameter(mesh.uv); // No effect.
Anyways, having to replace the entire array causes all sorts of garbage, requiring the GC to always need to Collect(), which ultimately results in frame rate dips (especially on mobile devices)...
Any way to get around this "messy" process? Or should I just keep the mesh uv modifications to the initialization phase of my scenes?
Answer by fffMalzbier · Apr 29, 2015 at 02:45 PM
You have to overwrite the whole array like you described.
But you can reuse the Vector2[] variable you for writing the uv's so you do not get the GC problems you mentioned.
The problem with this approach is that if the array is a different size or needs to be resized frequently if the user needs to update the mesh for wtv reason (i.e. terrain modification), then you run into GC problems again.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Drawing emojis with Unity's Dynamic Font 1 Answer
Creating a custom mesh - Cleaning the mesh failed 2 Answers
Picking up an object by it's center 2 Answers