Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 losingisfun · Jul 25, 2018 at 05:04 AM · uibuttonmousebuttons

Buttons and Event Triggers kill FPS

I'm moving the camera like so:

 void Update () {
 
             float moveX = 0f;
             float moveY = 0f;
 
             if (moveCameraUp || Input.GetKey (KeyCode.UpArrow) || Input.GetKey (KeyCode.W)) {
                 moveY += options.cameraSensitivity;
             }
             if (moveCameraDown || Input.GetKey (KeyCode.DownArrow) || Input.GetKey (KeyCode.S)) {
                 moveY -= options.cameraSensitivity;
             }
             if (moveCameraLeft || Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.A)) {
                 moveX -= options.cameraSensitivity;
             }
             if (moveCameraRight || Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D)) {
                 moveX += options.cameraSensitivity;
             }
             if (moveX != 0f || moveY != 0f) {
                 Vector3 pos1 = Camera.main.transform.position;
                 pos1.x += moveX;
                 pos1.y += moveY;
                 Camera.main.transform.position = pos1;
             }
 }

And the camera has been working very well. However, I noticed that when the mouse is hovering over a button on the Canvas UI, the frames will drop down to around 20 fps. As soon as I move the mouse off the button, it continues to move around effortlessly at over 100 fps.

I've also noticed that if I keep the camera stationary, and simply keep the mouse moving over the button UI, the frames will continue to drop, usually around 40 fps, and as soon as I stop moving the mouse, or move it off the button, it returns to normal.

I'm wondering if this is normal? Is Unity suppose to have such extreme performance issues with simple buttons? or could this be another underlying issue?


EDIT: I've now noticed that it is only with buttons that have Event Trigger components attached. I'm using these to detect when the mouse is hovering on the button, and display tooltips and such. Is there perhaps another way to do this?

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 Sonky108 · Jul 25, 2018 at 06:29 AM 1
Share

It shouldn't have so much impact. Could you post part of the code responsible for event trigger methods?

avatar image Piyush_Pandey · Jul 25, 2018 at 01:22 PM 0
Share

As the UI buttons code is not here, i will give you a small suggestion in your current code. Always cache Camera.main.transform.position; . Never use it in Update. This is not responsible for your lag but is a bit more efficient.

avatar image RLin Piyush_Pandey · Jul 25, 2018 at 03:45 PM 0
Share

It may actually be responsible for some of the lag. Camera.main internally calls FindGameObjectsWithTag, which is extremely inefficient to be used every frame.

avatar image Piyush_Pandey RLin · Aug 03, 2018 at 07:38 AM 0
Share

Agreed, but it will not cause a drop in 20 FPS.

0 Replies

· Add your reply
  • Sort: 

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

159 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 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 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

How to disable button animation fade? 1 Answer

How to make UI buttons so my player can move along certain lines 0 Answers

How to ADD one Buttons.onClick events to another Buttons.onClick? 1 Answer

Get button under mouse 1 Answer

UI Buttons - affects all 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