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 deeds0l · Mar 14, 2014 at 09:56 AM · c#arraylistscollection

How to assign List>Vector3>[]

Hi am assigning an array of lists

 List<Vector3>[] paths = mp.vectorPaths; //where mp.vectorPaths is a List<Vector3> []

but I keep getting this error:

Cannot implicitly convert type UnityEngine.Vector3[][] to System.Collections.Generic.List<UnityEngine.Vector3>[]

What does this error mean

Comment
Add comment · Show 3
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 darthtelle · Mar 14, 2014 at 10:28 AM 0
Share

Have you made sure to include "using System.Collections.Generic" at the top of your file? Also is mp.vectorPaths also of type List? If it's not then you'll have to fill your List manually.

avatar image Benproductions1 · Mar 14, 2014 at 10:42 AM 0
Share

List detonates a List type variable, while T[] detonates a built-in array type variable.

List[] is a array of lists

avatar image united4life · Mar 14, 2014 at 10:45 AM 0
Share

Use List>Vector3> paths = new List>Vector3>();

2 Replies

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

Answer by benni05 · Mar 14, 2014 at 10:42 AM

Your mp.vectorPaths is not a

 List<Vector3>

even though you might think it is. To prove this post the declaration of mp.vectorPaths here as well or double check. mp.vectorPaths is a 2-dimensional Vector3 array as the error message clearly says.

To make

 <>

working, mark it as code sample.

Comment
Add comment · Show 5 · 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 deeds0l · Mar 14, 2014 at 11:52 AM 0
Share

I found out that mp.vectorpath is declared as

  public Vector3[][] vectorPaths;

Is there any way I could assign it to my

 List<Vector3>[] paths
avatar image benni05 · Mar 14, 2014 at 12:40 PM 1
Share

Ok, yes, that's what I said. In general to make your Generic List work you would declare and fill it like this:

 List<Vector3> paths = new List<Vector3>(); // empty now
 paths.Add(new Vector3(1f,1f,1f)); // adding an example Vector3

You cannot assign a 2-dimensional array to your List just so. You could run in a nested loop over the 2 dimensions and fill your List with it. Also what are those 2 dimensions expressing? Guess you have to tell me why do you need the List, why is vectorPaths 2-dimensional and why would you like to put the contents of it into the List.

avatar image Benproductions1 · Mar 14, 2014 at 01:02 PM 2
Share

To make things nice, you could also use .ToList() from Linq

avatar image benni05 · Mar 20, 2014 at 08:51 AM 0
Share

Linq expressions can work but be careful though, they seem not to be supported on all platforms equally. See http://answers.unity3d.com/questions/376884/using-linq-when-building-to-ios.html

[1]: http://answers.unity3d.com/questions/376884/using-linq-when-building-to-ios.html

avatar image whydoidoit · Mar 20, 2014 at 09:01 AM 1
Share

Linq works fine on iOS with .NET subset so long as you don't use Sum (although Aggregate works fine). There may be other edge cases with complex joins, but I've had no issues apart from that.

avatar image
0

Answer by restush96 · May 11, 2021 at 05:25 PM

You can use this

 public List<Vector3> vector3s = new List<Vector3>() { new Vector2(1, 0), new Vector3(2, 9), new Vector3(5, 7,10) };
Comment
Add comment · 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

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

27 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

Related Questions

Problem with Web GL Build 1 Answer

How to check if a value exists in an array (C#) 3 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Affect every object in array. 1 Answer


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