I’m trying to create a list of quaternions. I need to be able to add and remove quaternions at any time, so I don’t want to use an Array. But I seem to be getting NullReferenceExceptions no matter what I do.
Here’s a simple example:
q = Quaternion(1, 0, 0, 0)
print(q.ToString()) # Works fine
qList = [] as List[of Quaternion]
qList.Add(q) # Crashes here with NullReferenceException: Object reference not set to an instance of an object.
Here’s another example:
q = Quaternion(1, 0, 0, 0)
print(q.ToString()) # Works fine
qList = [q] as List[of Quaternion]
print(qList.ToString()) # Crashes here with NullReferenceException: Object reference not set to an instance of an object.
Note that if I remove as List[of Quaternion]
from that second example, it works, but then the compiler only sees qList as a list, so the following then doesn’t work:
def methodThatTakesQList(qList as List[of Quaternion]:
print(qList.ToString())
q = Quaternion(1, 0, 0, 0)
print(q.ToString()) # Works fine
qList = [q]
methodThatTakesQList(qList) # The best overload for the method 'methodThatTakesQList(Boo.Lang.List[of UnityEngine.Quaternion])' is not compatible with the argument list '(Boo.Lang.List)'.
If I remove the as List[of Quaternion]
, this example perfectly works too, but I’d like to actually use some methods of quaternions (IE, multiplying them together) which fails the compilation type-check, since it sees it as me just trying to multiply objects together.