Recursive calling code raises "type could not be resolved because of a cycle" error.

The following code contains a recursive call. It is supposed to contain a recursive call. However; trying to use it did bring up a Unity error.

“Definition of ‘DrawGrid.Calc(index, Array, int, int, index)’ depends on ‘DrawGrid.Calc(index, Array, int, int, index)’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.”

Anyone know how to resolve this? Please note that “index” is a custom struct which is essentially a Vector3 that always only contains integers (made to store locations in a 3D array). The coroutines/subfunctions called here all work on their own; just this recursive call that’s failing (unfortunately, yes; a recursive call is probably necessary to do what I need done). Also note; the b : Array contains all the data for the game is being passed inbetween every subroutine like a football, because I don’t know how to make it statically accessible and editable by all functions otherwise.

function Calc (e : index, b : Array[], a : int, iteration : int, f : index){
	yield WaitForFixedUpdate ();
	var c : index [] = adj6 (e,f);
	a++;
	for (var d : int = 0;d < c.Length;d++) {
		if (c[d].iteration < iteration && c[d].active) {
			editdist (c[d], b, a, iteration);
			Calc (c[d],b,a,iteration,f);
}}}

1 Answer

1

The type for Calc is IEnumerator since you’ve made it a coroutine, so explicitly declare that as the type.

Also note; the b : Array contains all the data for the game is being passed inbetween every subroutine like a football, because I don’t know how to make it statically accessible and editable by all functions otherwise.

public static var stuff : Array[];

However you shouldn’t use the Array class; use generic Lists instead.

IEnumerator worked... public static var x : Array[]; Ended up with "object reference not to an instance of an object" when popping a single struct out of the object x[0][0][0] for example...unless the call was inside the Start or Awake functions. EDIT: found the problem; initiated x twice; once in the Awake() and redundantly in the Start(), engine was confused as to which of the two I meant.