- Home /
Array Problem - Error Code BCE0022
Hai people. I'm making a game in Unity (what else would you be making) and I don't quite understand the error. Or at least how to fix it. So, does anyone of you generous little people know the solution?
Here's my/the code I wrote/written (I like using slashes, they look awesome).
// Use this for initialization
function Start () {
GameObjectDisappear = GameObject.FindGameObjectsWithTag ("DisappearingObject001");
arr.Push("GameObjectDisappear");
}
var GameObjectDisappear : GameObject ;
var arr = new Array ();
// Update is called once per frame
function Update () {
}
function OnTriggerEnter (other : Collider) {
Destroy (GameObjectDisappear) ;
}
If you find the solution, you get a telepathically taste-transmitted cookie (don't ask how I got your brain's phone number). And a smile. :)
Answer by Matt-Downey · Jul 15, 2012 at 03:30 AM
I think you might be able to get this to work with fixed arrays. Usually with the javascript arrays you use float, int, string, etc (not GameObject from what I know).
var arr : GameObject[]; //make a fixed array
arr = new GameObject[1]; //resize the array to 1;
arr[0] = GameObjectDisappear;
you won't be able to see it in the editor, but at least you might not get the error.
You can't resize the array that easily though =( plus you can't use stuff like "push," you have to assign manually.
[edit:]Also, from what I remember, an object cannot "die"/be destroyed until all of the references to it are gone, thus the destroy function might behave oddly, since it has a reference in the array you are making. If you are trying to memorize which coins have been collected in a platformer, or something like that, try getting two fixed arrays, one with a boolean called collected? and the other with a vector3 called position (or something like that).
Your answer
Follow this Question
Related Questions
Array Problem - Error Code BCE0022 2 Answers
variable with int value not passing to command 1 Answer
Variable value as code?! 1 Answer
Add a Prefix to a Variable 1 Answer
How to get a value from an array within another script. 1 Answer