I have encountered a very strange behavior when addressing a single entry in a Quaternion[ ] Array.
If I copy one Quaternion[ ] to another like in the following example, everything works as expected.
However, when I adress single entries (which I need to later loop through the entire array and lerp between the single quaternions), the entry is not overwritten as expected.
Most strangely, this leads to the result that RightHandRotationsGoal is no longer overwritten with ListOfRightHandRotations[CurrentGestureRight] at the specified index (1 in the example) when changing CurrentGestureRight in the inspector. There is no error or warning message on the console.
Quaternion[][] ListOfRightHandRotations; // filled with data from .csv-file
Quaternion[] RightHandRotations;
Quaternion[] RightHandRotationsGoal;
public int CurrentGestureRight;
void Update()
{
RightHandRotationsGoal = ListOfRightHandRotations[CurrentGestureRight];
RightHandRotations = RightHandRotationsGoal; // works
RightHandRotations[1] = RightHandRotationsGoal[1]; // does not work
}
Is there any explanation for this, or is this a bug? I am using Unity 5.5.0f3.
Works fine for me
ofc, instead of loading from a csv im just filling the jagged array with simple (non-real) quaternions, but its just for testing, and every thing logs as expected
Quaternion[][] array2d;
Quaternion[] arrayOne;
Quaternion[] arrayTwo;
public int currentIndex = 0;
void Start () {
array2d = new Quaternion[3][];
for ( int i = 0; i < 3; i++ ) {
array2d[i] = new Quaternion[] { new Quaternion( 0, 0, 0, i + 1 ), new Quaternion( 0, 0, 0, i + 2 ) };
}
}
void OnGUI () {
if ( GUILayout.Button( "click now" ) ) {
arrayOne = array2d[currentIndex];
Debug.Log( arrayOne.Length + " = " + array2d[currentIndex].Length );
Debug.Log( arrayOne[0] );
arrayTwo = arrayOne;
Debug.Log( arrayTwo.Length );
Debug.Log( arrayTwo[0] );
arrayTwo[1] = arrayOne[1];
Debug.Log( arrayOne[1] );
Debug.Log( arrayTwo[1] );
}
}
Thanks for your Responses! @hpjohn : Your code logs as expected on my Computer, too. @TaleOf4Gamers_1 : Yes, the array is initialized and has 22 indexes, and logging any of these Indexes behaves as expected as Long as I don’t Change single Indexes as described.
So unfortunately, this strange Problem persists. Is there anything else that might cause it?