Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Gabz · Jan 14, 2015 at 07:11 PM · transformlagframeratechildrenrotatearound

Android game lags when using transform.RotateAround to rotate an object with many children

I am making a 2D mobile game that features many different levels and I'm using sprite tilesets to keep Draw Calls low. There's a particular level that I want to make part of the walls rotating so I grouped all the walls tiles (each wall tile being a separate GameObject) inside an empty GameObject and applied a rotation script to the parent. It works fine on the editor but when I test the game on an Android phone it lags a lot. The FPS on the Android version goes down to 20 and, the game being an action game, renders that level unplayable. Each parent GameObject has about 80 children inside of it (because the walls are composed of a lot of tiles), and the level has 3 sets of rotating walls. If I disable some of the wall tiles inside the rotating parents, the FPS normalizes, so I think the problem is the CPU is having a rough time rotating all these children GameObjects, but I don't know how to fix it.

This is the code that I use to rotate the walls:

public class SpinAround : MonoBehaviour {

 Vector3 center;
 public float distance;
 public float speed;
    //defines direction of the rotation
 public int sentido = 1;
 Transform myTransform;


 void Awake()
 {
            //defines the center of the rotation movement based on variable distance
     myTransform = this.transform;
     center = new Vector3(myTransform.position.x, myTransform.position.y, myTransform.position.z);
     myTransform.position = myTransform.position + myTransform.up * distance; 
 }

 void Update () 
 {

     transform.RotateAround(center, transform.forward, speed * sentido * Time.deltaTime);
 }

}

Why is this happening? How can I make this rotating wall issue more optimized? Is RotateAround a heavy method? How could I avoid this lagging problem without changing the way I build levels (with many GameObjects composing the tiles of a wall)?

Thanks in advance for the help.

Comment
Add comment · Show 4
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 Nimred · Jan 14, 2015 at 09:22 PM 0
Share

Are the game objects rigid bodies? Do they have colliders? I read in the manual that game objects with colliders but no rigidbody are considered "static", and are optimized as such, so rotating or moving them could cause performance issues. If it matches your situation, an easy fix is to add a rigid body component (with kinematic = true) on your wall tiles.

avatar image Gabz · Jan 15, 2015 at 02:23 PM 0
Share

The objects have colliders but don't have rigidbodies. I've tried adding kinematic rigidbodies but the framerate got worse. Also, I don't know if this influences anything, but I'm using Collider2D and Rigidbody2D in this project.

avatar image Nimred · Jan 15, 2015 at 02:37 PM 0
Share

Actually, maybe it's best to have one single rigidbody component on the wall ins$$anonymous$$d? Then all the children's colliders will be linked to that rigidbody. I don't know if the static collider issue applies to 2d, but it's worth a shot.

Also, have you confirmed that the framerate is better when the rotate line is commented?

Aside from that, and unless you can use the profiler in Unity pro, all I can think of is reducing the number of tiles :)

avatar image Gabz · Jan 15, 2015 at 02:48 PM 0
Share

Yes, commenting out the rotate line normalizes the framerate.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by khos85 · Jan 14, 2015 at 11:04 PM

Or have you tried moving: transform.RotateAround(center, transform.forward, speed sentido Time.deltaTime);

into FixedUpdate instead of Update Function, Update is called more often if understand correcly.

Hope that helps.

Comment
Add comment · Show 7 · 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 Gabz · Jan 15, 2015 at 02:33 PM 0
Share

I've tried moving that function to a Fixed Update and the framerate got really worse. That really didn't work unfortunately.

avatar image khos85 · Jan 15, 2015 at 02:45 PM 0
Share

Hmm, so does the whole game lag or only the object rotating?

avatar image Gabz · Jan 15, 2015 at 02:50 PM 0
Share

Everything lags, the framerate goes down to about 20-15 fps.

avatar image khos85 · Jan 15, 2015 at 06:21 PM 0
Share

Do you have a lot of tris/polygons in your scene that are in view of camera when rotating? can yu show me a stats windows in editor when running it in the editor?

avatar image Gabz · Jan 15, 2015 at 07:43 PM 0
Share

I have about 160 Tris and 330 Verts in the in view of camera when rotating.alt text

stats-mosquinha-donuts.png (72.9 kB)
Show more comments
avatar image
0

Answer by thirdstatestudio · Dec 22, 2015 at 01:09 PM

I have encountered the same problem and tried so many things to set it. Finally found out that OpenGLES3 is causing the lag. Go to player settings --> Android settings --> Other settings --> Unmark Auto graphics API and delete OpenGLES 3 from the list.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How Should I Get a List of Child Objects 2 Answers

Getting transform info after branch 1 Answer

Accessing children of instances vs children of original prefab 1 Answer

Rotation promlems past 90 and 270 3 Answers

Is there any way to use parenting as an organization tool without creating a Transform bond? 3 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