Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ArtOfWarfare · Oct 26, 2014 at 05:44 PM · listquaternionboo

List of Quaternions - NullReferenceException with types or type check errors without?

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArtOfWarfare · Oct 29, 2014 at 09:10 PM 0
Share

I'm finding that it's best to just avoid lists altogether... they cause an unnecessary impact on performance and a lot of Unity just doesn't seem to play nicely with them.

avatar image Bunny83 · Oct 29, 2014 at 09:38 PM 0
Share

For further questions that are boo related, you might want to include something like [boo] in the title. Boo questions are quite rare, so if there are people around that actually use boo, it's unlikely that this person will click on your question.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Oct 29, 2014 at 09:35 PM

What you are doing there makes not much sense. A List and an array are two seperate things. What you do here is creating an array and then use the as-cast to cast it into a List. However since an array is not a List this cast will fail. And one of the properties of the as-cast is that it will return null if a cast is not possible.

I'm not familiar with boo at all (like most people here). However from what i read the as-cast works the same as in all .NET / Mono languages.

What you actually want is creating an instance of a List. This should look like this:

 qList = List[of Quaternion]()

Usually the generic List also has a ToArray method if you need a built-in array from that list. However since boo has it's own List implementation it might be different.

edit
Little correction ;) the [] brackets seem to create an untyped List and not an array. Anyways the same problem: a List is not a List[of Quaternion] so an as cast will fail.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArtOfWarfare · Feb 17, 2015 at 03:04 AM 1
Share

Thank you! I hit this same problem again months later and was going to post a new question, meanwhile thinking it has seemed like I had asked about this before. Checked my list of asked questions and lo and behold, I had! Tried your solution and it worked! Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Force typcasting of member objects in a List? (Boo) 1 Answer

List of Objects in Boo 0 Answers

How to Find an Object close to where the Player is Looking 1 Answer

Show boo list in inspector? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges