• 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
1
Question by ina · Feb 12, 2012 at 02:03 AM · inputtouchtypetemporary

Input - allocates temporary variable

What does it mean when the documentation refers to whether something "does not allocate temporary variables" vs "allocates temporary variables"

http://unity3d.com/support/documentation/ScriptReference/Input.html

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
2
Best Answer

Answer by Bunny83 · Feb 12, 2012 at 03:37 AM

Well, they refer to the fact that the touches and accelerationEvents properties of Input create an array out of the individual Touches. Here's how .touches is implemented internally:

 // C#
 public static Touch[] touches
 {
     get
     {
         int touchCount = Input.touchCount;
         Touch[] array = new Touch[touchCount];
         for (int i = 0; i < touchCount; i++)
         {
             array[i] = Input.GetTouch(i);
         }
         return array;
     }
 }

It's just a hint that it might be a performance overhead if you use this property multiple times each frame. If you just need the information of one specific touch you should use the GetTouch() method instead.

Comment
Add comment · Show 3 · 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 ina · Feb 14, 2012 at 09:41 PM 0
Share

So touches actually calls GetTouch... Curious, how do you know that that is what's implemented internally?

avatar image Bunny83 · Feb 14, 2012 at 10:35 PM 1
Share

Because the UnityEngine.dll and the UnityEditor.dll are .NET / $$anonymous$$ono assemblies which can be viewed with a .NET reflector like ILSpy

$$anonymous$$ost things in the Unity API are mapped directly to native code, which you obviously can't view. $$anonymous$$anaged code can easily be decompiled and "reflected". It's actually a feature of the underlying language CIL (common intermediate language).

However, always keep in $$anonymous$$d that the possibility of viewing / decompiling the assemblies doesn't change anything on Unity's copyright on that code, so respect it. Viewing some of the classes (esp. GUI, GUILayout) really helps to understand how it works behind the scenes.

avatar image ina · Feb 15, 2012 at 04:03 AM 0
Share

Wow, I"m not familiar with .NET in general, beyond Unity $$anonymous$$onoDevelop, so this is very interesting to learn. Would this be useful for answering questions like http://answers.unity3d.com/questions/209648/unity-engine-conditional-comparison-sign-evaluatio.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Samsung 42" Touch Screen: Touch response issues 1 Answer

Problem with Input.touchCount 0 Answers

How can I use Input touch for this script. 0 Answers

Why can't I press both my touch controls at the same time? 1 Answer

Touch Input help.. 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