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
0
Question by drudiverse · Mar 26, 2014 at 12:03 PM · arrayclassnew

Declare new class[].vector3[] length?

I have many arrays of Vector3's that represent many shapes, each shape is an arrays of dots:

 class Dots
 {
     var name : String;
     var dotarray: Vector3[];    
 }
  
  
 var shape : Dots[];

 shape =new Dots[10];//10 shapes

 for (var j:int = 0; j < 10; j ++){
     shape[j]=new Vector3[20];//20 dots per shape... this line crashes
 
 }    

BCE0022: Cannot convert 'UnityEngine.Vector3[]' to 'Dots'.

then i am supposed to access it in this way:

 var a_dot = shapej[shapeNumber].dotarray[dotNumber]
Comment
Add comment · Show 4
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 Fornoreason1000 · Mar 26, 2014 at 12:09 PM 0
Share

where did you get the variable "e" from?

avatar image drudiverse · Mar 26, 2014 at 12:43 PM 0
Share

hi, sorry that's just the total number of dots for every shape / each dotarray, i ll update question sry.

avatar image Simon-Larsen · Mar 26, 2014 at 01:16 PM 0
Share

When you want to create 20 dots per shape. Do you mean you want 20 points in space, as in 20 Vector3 objects? In that case you probably want to make an array of vector points. This question may be of help to you http://answers.unity3d.com/questions/673691/declare-new-classvector3-length.html

avatar image drudiverse · Mar 26, 2014 at 02:50 PM 0
Share

Thankyou Simon. I wish to have many shapes of each 20 dots, so that i can access the dot array from any shape using a shape array. The question that you referenced is the same page as this one.

2 Replies

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

Answer by trololo · Mar 26, 2014 at 01:31 PM

Array length = 10, iteration number = 20 : problem.

Comment
Add comment · Show 3 · 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 drudiverse · Mar 26, 2014 at 02:44 PM 0
Share

Thanks alot, you are right about that. It would have said "array out of range" I made a mistake in example code. With correct numbers this is the error:

BCE0022: Cannot convert 'UnityEngine.Vector3[]' to 'Dots'.

avatar image trololo · Mar 26, 2014 at 02:58 PM 0
Share

Well this is logic, it's not the same type! (as it's said)

 class Dots
 {
    var name : String;
    var dotarray: Vector3[]; 
         
    public Dots(var n : String, var d: Vector3[])
    {
     name = n;
     dotarray = d;
    }
 }
     
 // ...
     
 for(...)
    shape[i] = new Dots("lol", new Vector3[20]);
avatar image drudiverse · Mar 26, 2014 at 03:09 PM 0
Share

Brilliant Trololo, that's nice. There's a classes tutorial video from Unity, i hadn't totally figured it out still. Thank You.

here is more formal .JS code:

 class Dots
 {
     var dotarray: Vector3[];    
      public function Dots(  d: Vector3[])
    {
     dotarray = d;
    }
  
 }
  
 var shape : Dots[];
  
 shape =new Dots[10];//10 shapes
  
 for (var j:int = 0; j < 10; j ++){
     shape[j]= new Dots(new Vector3[20]);
 }   

shape[3].dotarray[4]= Vector3.up; // a test line

avatar image
1

Answer by diegzumillo · Mar 26, 2014 at 01:47 PM

There are only 10 shapes, so your for loop should be up tp 10, not 20. Also, you want shape[j].dotarray =new Vector3[20]; You already initialized shape in a previous line, inside the for loop you want to initialize the dotarray of each shape.

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

22 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

Related Questions

"Null Reference Error" when using a custom class as an array 1 Answer

Creating a class wide array (c#) 1 Answer

Resizable Array of Classes? 2 Answers

Need help setting an array of my class 0 Answers

Why cant i do this with an 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