Hi,
I’m trying to have some of my game objects’ meshes replaced on runtime in order to create some kind of animation (without using skeletons or other methods).
Let’s say for example that I have 10 game objects, each of the has a different mesh for each frame in their animation.
When I initialize my game I’m loading all of the meshes into a data class that holds all the meshes in a List and when I update the game objects I wanna do something like
MeshFilter filter = gameObject.GetComponent();
filter.mesh = nextMesh;
The problem with this use case is that the 2nd line doesn’t use the store mesh as a reference but instead it would make a new copy of the nextMesh so if I run it in a loop the memory usage will just explode.
I’m relatively new to Unity so I’m still learning the Unity way of doing things, I come from C++ and used to passing Mesh objects by pointer of reference although I’m pretty sure that in C# such an assignment is supposed to work “by reference” and not “by value”.
So what would be the right way to achieve this?
P.S I know that replacing meshes on a frame by frame basis sounds wasteful and isn’t the right way to animate something in a game. my use case here is a bit different so it has to work like this.
Thanks.