• 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 cineboxandrew · Apr 15, 2013 at 05:47 AM · loopunresponsive

Why wont unity respond after i added this simple logic?

i added this script to move all the blocks i my editor to another location, but unity now gives me the beachball of death like it its stcuk in a loop. what happened?

 function Update () {
     var septoggle = Input.GetAxis("separate");
     if (septoggle != 1) {
         for (var voxel : GameObject in voxelArray){ //iterates through objects in voxelArray
             var voxelLoc = voxel.GetComponent(voxelScript);//gets voxel origin location
             
             voxel.transform.position = Vector3(voxelLoc.x, voxelLoc.y * sep * septoggle, voxelLoc.z);    
         }
     }
 }
Comment
Add comment · Show 5
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 Eric5h5 · Apr 15, 2013 at 06:05 AM 0
Share

How many items are in voxelArray?

avatar image Loius · Apr 15, 2013 at 06:10 AM 0
Share

"voxel" implies that you have lots of these things

GetAxis probably is almost always zero, which isn't one, so most of the time you're running through a huge array, using a typeless variable (which maybe has to be dynamically typed, which introduces some slowdown), and using .transform (which introduces a tiny bit of overhead as opposed to just storing the transform). Classes should start with capital letters (consistency is very important to programmers) - is your script called VoxelScript? Printing tons of error messages each frame can cause a huge slowdown.

Depending on what is supposed to be happening, you may want to change that to != 0. You could also type voxelLoc (var voxelLoc : voxelScript =). Adding #pragma strict to the top of the script will help you avoid some hard-to-find issues with variable types.

avatar image Eric5h5 · Apr 15, 2013 at 06:13 AM 0
Share

There aren't any typeless variables in that code. It probably already has #pragma strict, or if not, it won't make any difference here.

avatar image cineboxandrew · Apr 15, 2013 at 10:39 PM 0
Share

turns out this code wasn't the problem, i removed #Pragma strict and the block above (generating voxel array) stopped running. i had to remove it because of the multiplication you see there. it thought one of those was an object preventing me to multiply it. ill try converting it to a value

Voxelscript is the script kept on the voxels themselves to store variables and such. is there a better way to do this?

avatar image Eric5h5 · Apr 15, 2013 at 10:47 PM 2
Share

Do not remove #pragma strict. Write code that works properly with it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by anilo · Apr 15, 2013 at 06:24 AM

The Update method is called 30 times per second (depending on your settings). So your move logic is running 1000's of times, that's why you see nothing else.

Perhaps you wanted to make the objects move only once. You can do that by moving your code to your Start() method. Then it will execute only once.

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 cineboxandrew · Apr 15, 2013 at 10:36 PM 0
Share

Thank you, it turns out the block of code i had before was reacting negatively to me removing #pragma strict. is there any way to have a funcion called only when, say, a key is pressed?

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

14 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

Related Questions

Audio after Audio Loop 1 Answer

how to stop animation loop? 1 Answer

Video Texture Loop 2 Answers

[ANSWERD] Sounds Loop with delay 1 Answer

Video Texture Loop on TV 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