- Home /
Array Shift error
I'm trying to use Array.Shift but I get this error: MissingMethodException: Method not found: 'UnityEngine.GameObject[].Shift'
var wps: GameObject[];
var currentWP: int;
var nPoint : Vector3;
var path : Array = new Array();
nPoint = wps[currentWP].transform.position;
currentWP = wps.Shift();
path.Add(currentWP);
Antone know why or how to fix it?
Answer by syclamoth · Dec 04, 2011 at 03:49 AM
This happens because the 'Shift' method is for Unity's 'Array' class, not builtin arrays. Built in arrays don't have that functionality. There are, of course, many other data structures which do- have a look at arraylists or lists.
I tried this, but I got an error: Cannot cast from source type to destination type.
The Change ---> var wps = new Array(GameObject);
The Error location ---> currentWP = wps.Shift();
use
var wps : GameObject[];
private var _wps : Array;
then in start-
_wps = new Array(wps);
Then you can use all your special arraylist functions on _wps, but still assign them in the inspector.
Ok, the problem is that Shift returns a GameObject, not an int! Why are you trying to get an int out of a gameobject?
currentWP should be a GameObject, not an int, if you want to use it with the Shift function this way.
Like a "for" loop, where if it reached the position of the waypoint, it adds to the int and forces it to move again?
Your answer
![](https://koobas.hobune.stream/wayback/20220613061747im_/https://answers.unity.com/themes/thub/images/avi.jpg)