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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by shame · Dec 24, 2012 at 12:27 PM · performancemonobehaviourextensioninherit

Would abuse of inheriting from extended MonoBehaviour hurt the performance?

 public class ExtendedMonoBehavior : MonoBehaviour
 {
     private static bool _isServer;
     public static bool isServer
     {
         get
         {
             if (_isServer == default(bool))
             {
                 if (UnityEngine.Object.FindObjectOfType(typeof(Server)) != default(UnityEngine.Object))
                 {
                     _isServer = true;
                 }
                 else
                 {
                     _isServer = false;
                 }
             }
 
             return _isServer;
         }
     }
 
     private static EventDispatcher _eventDispatcherComponent;
     public static EventDispatcher eventDispatcherComponent
     {
         get
         {
             if (_eventDispatcherComponent == default(EventDispatcher))
             {
                 _eventDispatcherComponent = (EventDispatcher)UnityEngine.Object.FindObjectOfType(typeof(EventDispatcher));
                 if (_eventDispatcherComponent == default(EventDispatcher))
                 {
                     throw new System.Exception("Can't find EventDispatcher in your scene");
                 }
             }
 
             return _eventDispatcherComponent;
         }
     }

     public static T[] ConvertToArray<T>(IList list)
     {
         T[] ret = new T[list.Count];
         list.CopyTo(ret, 0);
         return ret;
     }

     public static Dictionary<GameObject, GameObjectParameters> networkedGameObjectsWithParameters = new Dictionary<GameObject, GameObjectParameters>();
     public static Dictionary<NetworkPlayer, NetworkPlayerParameters> networkPlayersWithParameters = new Dictionary<NetworkPlayer, NetworkPlayerParameters>();
 
     public static IControllable controlledComponent=default(IControllable); // client only
 }

so on and so forth... of course i have all my scripts inheriting from it. I could put them into other script using extension methods instead. would that make me cry in the long run?

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 MaGuSware™ · Dec 24, 2012 at 01:12 PM 1
Share

I honestly hope not, because ive done something similar but with Character$$anonymous$$otor.

Realistically speaking though, its just an inherited class. The only performance problems would be caused with bad coding practices.

1 Reply

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

Answer by MarkFinn · Dec 26, 2012 at 06:49 AM

There's no technical reason that this shouldn't be ok. It will make your code more complex over time, but that's down to being strict with your code standards.

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

10 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

Related Questions

Having runtime functionality and editor extension in one script 1 Answer

MonoBehaviour Update() performance vs handling updates in a single UpdateManager script 0 Answers

Component extension methods not showing 1 Answer

MonoBehavior, ScriptableObject and Object memory usage & performance 0 Answers

Efficient way to scan surrounding with large number of objects 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