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 /
This question was closed May 25, 2016 at 12:12 PM by coolraiman for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by coolraiman · Feb 02, 2016 at 04:42 PM · c#uibuttoneventsystem

inheritance vs multiple component for UI

hi, this is mostly a question about performance of the unity event system for UI

i am currently making an effect button class to add various effect like shaking, resize, AnimatedSpriteButton

my current design is abstract class ButtonEffect : MonoBehaviour , IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler , IPointerUpHandler

this main class deal with most of the basic stuff.

by exemple:

 public bool IsActive
     {
         get{return isActive;}
         set
         {
             isActiveChanged();
             isActive = value;
         }
     }
     //function called when isActive value is changed from the outside, must be implemented by all child class
     protected abstract void isActiveChanged();

most of the function are virtual and also manage some boolean like isPressed and isInside

then i have a child class like Button resize that use all these function and data to do what it has to do I can then have multiple different child as different component of different complexity on the same uibutton

by example i have the button spin with these 2 components: ButtonResize : ButtonEffect and ButtonAnimatedSprite : ButtonEffect

each component is independent but here is my question since each component derive from ButtonEffect, each component OnPointer event function calls will be duplicated and i heard that it is much slower than regular c# event

Should i keep this design or instead change my abstract ButtonEffect for non abstract ButtonEvents and all button effect will instead of inheriting from ButtonEvents will RequireComponent ButtonEvents and subscribe to various event raised by ButtonEvents class. this way, for each button, all unity OnPointer event will only be called once, then each button effect will subscribe to the event he need

My game is on webgl so optimisation is a must

thank you for your time

Comment
Add comment · Show 1
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 cjdev · Feb 03, 2016 at 09:39 AM 1
Share

An event is just a delegate, sometimes wrapped up in layers of abstraction, but still just a method call at the end. Yes, it can cost performance when doing it every frame in an Update loop or something similar but for buttons with discrete click events you probably won't notice any difference. It's more of a design decision and whether or not you want there to actually have to be two events fired for the same reason in the first place.

1 Reply

  • Sort: 
avatar image
0

Answer by SunnyChow · Feb 03, 2016 at 04:46 AM

The component system is designed for designer-friendly, instead of performance. So Yes, the less components you use, the better performance you have. But i don't think there is much improvement you can do in UI. Try do the optimisation on game mechanic first.

Comment
Add comment · Show 1 · 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 coolraiman · Feb 05, 2016 at 04:32 PM 0
Share

in webgl when your main target is woman between 30 to 40, you have to make the game for low end pc. Every bit of optimisation count

Also, it is not just a question about performance but also good design

currently im going with the first option Each button effect is more independent and with abstract functions and simple override it look faster and im sure everything is implemented correctly.

We dont have any game level designer, i do all the client side code for the visual

Follow this Question

Answers Answers and Comments

76 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

Related Questions

UI works in editor, but not on mobile device 1 Answer

I made an resume button, but I don't know how to code it to close my pause menu, any tips? 2 Answers

I need to move a sprite when an UI button is clicked 1 Answer

Change the position of a UI component through pressing a UI Button 1 Answer

Unity - destroy clone child object (button) 1 Answer


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