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 sniper43 · Mar 02, 2015 at 02:36 PM · performance optimizationexecution-order

Execution order vs script insurance

I've got a custom input manager. I already know that the optimal solution would be to configure it in the execution order. But I'm asking whether the overhead penalty is huge enough to be considered problematic.

Alternatively, is there a way to "auto-add" a script to the begining of the execution order via the script iteself?

Ideally I want this to be a drag and drop script and work 100% script.

Here is the code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 /// <summary>
 /// DO NOT USE INPUTS IN LATEUPDATE WITH THIS INPUT MANAGER
 /// Only handles buttons - use default Input Manager for mouse movement and joystick movement
 /// </summary>
 public class MyInputManager : MonoBehaviour
 {
     #region SingletonMethod
     private static MyInputManager _instance;
     
     //This is the public reference that other classes will use
     public static MyInputManager instance
     {
         get
         {
             //If _instance hasn't been set yet, we grab it from the scene!
             //This will only happen the first time this reference is used.
             if(_instance == null)
                 _instance = GameObject.FindObjectOfType<MyInputManager>();
             return _instance;
         }
     }
     #endregion
 
     public AxisElement[] Axes;
 
     private Dictionary<string, float> Axis = new Dictionary<string, float>();
     private Dictionary<string, float> AxisPrevValue = new Dictionary<string, float>();
 
     private bool ranUpdate;
 
 
     private void Start()
     {
         foreach( AxisElement ae in Axes )
         {
             Axis.Add(ae.name, ae.axisValue );
         }
     }
 
 
     private void Update()
     {
         if(!ranUpdate)
         {
             foreach( AxisElement ae in Axes )
             {
                 
                 AxisPrevValue[ae.name] = Axis[ae.name];
                 Axis[ae.name] = 0f;
                 foreach(KeyCode kc in ae.PositiveKC)
                     if( Input.GetKey( kc ) )
                     {
                         Axis[ae.name] = 1f;
                         break;
                     }
                 foreach(KeyCode kc in ae.NegativeKC)
                     if( Input.GetKey( kc ) )
                     {
                         Axis[ae.name] = -1f;
                         break;
                     }
                 
             }
             ranUpdate = true;
         }
     }
 
     private void LateUpdate()
     {
         ranUpdate = false;
     }
 
     public float GetAxis(string identifier)
     {
         Update();
         if( Input.GetAxis( identifier ) != 0f )
             return Input.GetAxis( identifier );
         else
             return Axis[identifier];
     }
     public float GetAxisNoUniMan(string identifier)
     {
         Update();
         return Axis[identifier];
     }
     public bool GetButton(string identifier)
     {
         Update();
         return Axis[identifier] != 0 || Input.GetButton( identifier );
     }
 
     public bool GetButtonDown(string identifier)
     {
         Update();
         return ( Axis[identifier] != 0 && AxisPrevValue[identifier] == 0 ) || Input.GetButtonDown( identifier );
     }
     public bool GetButtonUp(string identifier)
     {
         Update();
         return ( Axis[identifier] == 0 && AxisPrevValue[identifier] != 0 ) || Input.GetButtonDown( identifier );
     }

}

The script works 100%, does not require any adjustment and inputs can be changed on the fly.

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 Landern · Mar 02, 2015 at 02:51 PM

You can script the execution order, an answer by FlyingOstriche on the forums solves with an with added attribute. You probably won't get bend out of shape by the small "hit" you take by customizing the order of execution.

Forum post to Script Order Execution Editor Script.

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 sniper43 · Mar 02, 2015 at 03:14 PM 0
Share

Thanks for the quick response. Exactly what I wanted, I can use this for a lot more as well.

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

20 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

Related Questions

Can I force unity to "weld" or "attach" a vertex of common faces, just like 3ds max? 1 Answer

what is more important for performance in Unity? UV count or the Vertice count 1 Answer

Code Performance: When to use "new" on Vector3 3 Answers

Reading Profiler Results 1 Answer

Help with Optimizing Voxel Code? 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