- Home /
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
Is any code that you have not shown us also using this array?
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?
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. :)
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.
Your answer
Follow this Question
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