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 Hambag · Aug 05, 2014 at 05:19 AM · arrayvector3vectorchildren

Filling an array with child vectors

I'm trying to store some vectors into an array. Here's what's going on:

image1 image2

The orange cylinder is the main object "Waypoint", with the blue "View" objects as its children. In a script applied to the waypoint, I declared an array of Vector3's, got the children of the object, and got each one's transform.forward vector. The funny thing is that when I print it, I get four Vector3's, just like I'd expect. However, when I try to actually put those inside the array, it gives me this error:

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

What I can gather from this is that I might be accidentally trying to convert the array into a vector3, but I don't know what the proper syntax would be. Here's my script so you get the idea:

 public var cameraAngles : Vector3[];
 
 function Start ()
 {
 
     for (var children : Transform in transform)
     {
     
     cameraAngles = children.transform.forward;
     print(children.transform.forward);
     
     }
 
 }


Comment
Add comment
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

2 Replies

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

Answer by Hambag · Aug 05, 2014 at 09:08 AM

I solved it by just switching over to javascript arrays instead of built-in ones. I hope it doesn't affect performance too much.

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
avatar image
0

Answer by robertbu · Aug 05, 2014 at 02:43 PM

Do not use the Array() class. It is slow and untyped and there is nothing it can do that you can't do with other classes. If you need and array that varies in size, use one of the .NET generic collections. Typically the List class is used. Here is more information on collections in Unity:

http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F

Here is a bit of code that uses built-in arrays:

 #pragma strict
  
 private var cameraAngles : Vector3[];
  
 function Start () {
      cameraAngles = new Vector3[transform.childCount];
      var i : int = 0;
     for (var child : Transform in transform)
     {
      cameraAngles[i++] = child.forward;
     print(child.forward);
     }
 }

Note that I made 'cameraAngles' private since you are initializing it in start. Also with the public array, you have just dragged and dropped the children into the array in the Inspector and not done the initialization in start.

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I make an array of vectors? 1 Answer

Declaring a Vector3 variable in C# 1 Answer

How do you find one Vector's position of an Array? 1 Answer

Vector4 values disappearing from Array, Unity C# bug? 1 Answer

Looking for a to check a list of vector3's quickly. 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