Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by raj_alahmar · Oct 30, 2015 at 06:07 PM · animation2dgameobjectshape

Best way to change the shape of an object at runtime

Helo guys.

I am new to unity. I want create a simple 2d game. 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.

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 better:

  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.

lel.png (7.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Taxen0 · Oct 30, 2015 at 07:56 PM

Not exactly sure how you want this to happen, but if the objects should appear at the same place all the time you can make child objects and simply enable/disable them.

For example: the default state, the big circle is the parent object. And the smaller circles and rectangle would be their own child objects that you can enable by script when you want the object to grow, and of course the other way around.

If the player should be able to add different objects wherever they want a more advanced system would be required.

Hope this helped a bit!

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image raj_alahmar · Nov 01, 2015 at 10:20 AM 0
Share

$$anonymous$$y apologies, the description was not detailed enough. Firstly, thank you for your answer, it's very helpful.

  1. The objects will not be placed in the same place all the time, they will move (but each child will still be attached to the same "parent" object).

  2. The growth of the whole entity is dependent on a variable (i.e speed) that changes at runtime. Is there an easy way to provide the object with this variable as a property so that it would grow and shrink with a speed matching it?

  3. The target platform is Android and I am not sure of the performance if there will be let say 10 gameobjects in the scene, each having a couple hundred children?

avatar image Statement raj_alahmar · Nov 01, 2015 at 12:35 PM 0
Share

The target platform is Android and I am not sure of the performance if there will be let say 10 gameobjects in the scene, each having a couple hundred children?

$$anonymous$$ake a dummy test with 10x200 rendered game objects and measure performance with the profiler or the internal profiler. If the test is too slow, try to figure out how to make it faster. Look at where time is spent and tackle the biggest issues first.

Edit: There are lots of different android devices, with varying performance and capabilities. Testing performance on one specific device will give you an idea if the game will run on that device or better devices. However, if you are going to be serious and release a game on the market you should make the performance tests on the lowest perfor$$anonymous$$g android device that you want to support, to ensure that the lowest hanging fruit can play the game.

avatar image raj_alahmar Statement · Nov 01, 2015 at 01:16 PM 0
Share

Thank you for your suggestion.

The problem is not only with the amount of objects, but with the fact that they will also all have to move constantly. As I said in the comment below, their growth/shrinking behavior will be triggered by some events. Having GameObjects with children would require enabling/disabling them very frequently; how will this affect the performance?

Their behavior will be rather repetitive: each entity will grow and shrink the same way throughout the game.

I will test it but if you have any more suggestions I'd be glad to hear them too.

Show more comments
avatar image Taxen0 · Nov 01, 2015 at 12:22 PM 1
Share

I guess there are a few ways to do it depending on how dynamic you need the changes to be.

If the objects should change shape in a set pattern I would probably do an animation and loop that. Or jump to the different frames when you need to change state.

Should you need more control and change the object to all kinds of crazy shapes depending on user input or something, so it would be too much work to make a seperate image for each state imaginable, a setup where you enable / disable the child objects as needed would probebly be better.

Try to explain what kind of game it is and how it works if you need more help. :)

avatar image raj_alahmar Taxen0 · Nov 01, 2015 at 01:21 PM -1
Share

The changes won't have to be very dynamic.

It doesn't depend on the player in any way -- each entity always grows and shrinks the same way repeatedly (kinda like in a loop). This behavior (growth and shrinking) is triggered by in-game events but normally the entities are idle.

avatar image Taxen0 raj_alahmar · Nov 01, 2015 at 11:54 PM 1
Share

Then you could simply make a animation, like a sprite and jump to the frame that have the look you want when you want it to change.

I recently started with mobile development myself so i have no clue regarding many objects and performance. But the sprite should be nice and quick.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Sprite animations flicker on first run in Unity 5.3 13 Answers

Can't seem to get my animations to work proper 1 Answer

Select Object And Spawn it 1 Answer

Unity 5 Animator hides Sprites on Android [Strange] 0 Answers

Help with 2D Enemy Animations 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges