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 /
avatar image
0
Question by Simon 9 · Sep 06, 2011 at 09:56 PM · arrayfreeze

Unity Freezes when accessing an Array in a different script GameObject

I create an Array in my "ModularParentScript" (js) like so:

 public var attachPointCount = 0; // Total available attach points on all objects
 public var attachPoints : Array; // The available attach points
 
 function Awake() {
     attachPoints = new Array(); // Create the array to hold the attach points
 }

Then, on a different object, I want to fill that array with the attach points (gameObjects) like so:

 parentScript = parentObject.transform.GetComponent( "ModularParentScript" );

These lines of code run just fine:

 myArray = new Array( parentScript.attachPoints ); // Grab the attach points array
 myArray.Add( theAttachPoint ); // Add an element (if I modified the original array directly it would freeze Unity)

However, this line (when un-commented):

 //parentScript.attachPoints = new Array( myArray ); // Put the modified  array back in the parent

Freezes Unity. So do these:

 //pointsArray = parentScript.attachPoints;
 //pointsArray.Push( theAttachPoint ); // Add attach point to the array
 //parentScript.attachPoints.Add( theAttachPoint ); // Add the point to the list on the parent


It seems any time I try to modify the array in the parent script, it freezes Unity (the kind where you have to Ctrl+Shift+Esc to close it and then reopen). What am I doing wrong here?

Thanks, Simon

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 Waz · Sep 06, 2011 at 11:28 PM 0
Share

Is any code that you have not shown us also using this array?

avatar image Simon 9 · Sep 07, 2011 at 12:28 AM 0
Share

No. I haven't done anything else to the array.

avatar image Waz · Sep 07, 2011 at 12:41 AM 0
Share

It sounds like the code is short. Could you post the entire file, without extra commented out stuff, of what doesn't work - test it first in a clean empty scene?

avatar image Simon 9 · Sep 15, 2011 at 01:00 AM 0
Share

Thanks for the tip, I tried it in a new scene and I think I've solved it. It was an infinite loop in the code that only operates when the attach-points array is not empty. :)

avatar image ericksson · Sep 15, 2011 at 01:05 PM 0
Share

You should post an answer to your question and have it voted up, so that the question doesn't stay in the Unanswered section forever.

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Turn based games turn manager is spazzing out 2 Answers

problem with FindWithTag 2 Answers

Problem with moving objects in array? 2 Answers

Unity freezes on play 2 Answers

C# Make array based on script variable 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