3

I want create a simple 2D game in Unity3D, in which one of the entities has to grow and shrink. This is done by merging simple shapes.

A rough example in the picture below just to show what I mean:

Image

It grows by adding components and shrinks by removing them. There will be a lot of entities on the screen so the performance is very important.

Is it possible to change dynamically the shape of one gameobject? If not, which of the following solutions is more suitable and why?

  1. Constantly add new gameobjects (shapes) to the previous one and then remove them?

  2. Create an animation. In this case is it possible to change the animation speed at runtime so for example first it grows faster and then grows slower or shrinks? My issue is whether the change of speed will apply to the whole loop of the animation or is it possible to apply it in the middle (so that the speed of shrinking and growing is different)? I would prefer the latter to happen.

If you have any other suggestions I'd be glad to hear them.

Raj Alahmar
  • 31
  • 1
  • 3

2 Answers2

1

Create an empty game object and add all of these small pieces as its child. Then you can disable/enable whichever you want with gameObject.SetActive(false/true);

kagkar
  • 469
  • 5
  • 15
0

Depends what is "lots of objects" and what is the target platform.

You can easily have hundreds of sprites on screen in any case, especially if they get batched : http://docs.unity3d.com/Manual/DrawCallBatching.html

And there is big performance benefit to use object pooling, instead of instancing new objects and destroying old ones.

Having hundreds of animated objects would cause slowdown, Mecanim Animator seems to be slower than the original Animation component.

Other options: - Create custom mesh that you modify at runtime (by adding/removeing vertices to it), this also allows to freely modify the shapes (by moving the vertices) : http://docs.unity3d.com/ScriptReference/Mesh.html

mgear
  • 1,333
  • 2
  • 22
  • 39
  • The target platform is Android. There are going to be about 10 entities per view so if I use animations there won't be enormous amounts -- just as many as there are entities. When using object stacking, I'd have several thousand objects (each parent object would have few hundred child objects) -- will using animations really be worse for the performance than having a few thousand game objects in this case? – Raj Alahmar Nov 01 '15 at 10:49