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 rednax20 · Mar 17, 2014 at 09:22 PM · arrayvector3push

Push a Vector3 array

I'm not quite sure what i've defined here,

 var vectorarray = [Vector3(0,0,0)];

i would think that it would be the same as

 var vectarray =new Array();

but evidently it is not, for, i have a script that i got off the internet wouldn't work if i used the latter (latter means second, to who were just confused)

I want to be able to push a value to that array, but if I use the first method i get the following error:

MissingMethodException: UnityEngine.Vector3[].Push

I usually define arrays the second way, so I'm not too sure what i have did in the first method, or why it isn't working

My actual goal is to put a value to the end of my vectarray

do you know of another method using the first way of defining arrays??

i went as far as to try this

 vectarray[vectarray.length] = Vector3(0,0,0);
 
 //sadly even this didn't work.

thanks.

.

.

.

.

.

.

.

Ps. This is the script i copied, it is part of playerprefsx

     // i don't know what much of it means, that's why i put this at 
     //the bottom as to not scare anybody,  i don't think you need to
    // know it to solve my problem.
     static function SetVector3Array (key : String, vector3Array : Vector3[]) : boolean {
         return SetValue (key, vector3Array, ArrayType.Vector3, 3, ConvertFromVector3);
     }
     
     //and that ConvertFromVector3 function is:
     
     private static function ConvertFromVector3 (array : Vector3[], bytes : byte[], i : int) {
         ConvertFloatToBytes (array[i].x, bytes);
         ConvertFloatToBytes (array[i].y, bytes);
         ConvertFloatToBytes (array[i].z, bytes);
     }
     
     //and ConvertFloatToBites is 
     
     private static function ConvertFloatToBytes (f : float, bytes : byte[]) {
         byteBlock = System.BitConverter.GetBytes (f);
         ConvertTo4Bytes (bytes);
     }
     
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · Mar 17, 2014 at 09:42 PM

Unity wiki: Which Kind Of Array Or Collection Should I Use?

 //built-in Vector3[] array
 var vectorarray = [Vector3(0,0,0)];

 //JavaScript Array()
 var vectarray = new Array();

Personally, I'm a big fan of static typing (especially considering that JavaScript's dynamic typing isn't well-supported on mobile), which means that I scratch and hiss at any code that uses Array(). Its performance is less than ideal, and I have no sure idea of what's in it.

Built-in arrays have a fixed size once they're created, which is why there's no Push() function for them. These are much closer to the traditional arrays you'll see in languages like C++. They have excellent performance if you know the size of the array ahead of time.

If you're fine using Array(), that's okay. Really not my thing, but plenty of people use it.

One step up, in my opinion, is to use a generic list, or List. This still guarantees that everything in the list has a particular type, but also allows you to add and remove items, resize the list, and so on. In many cases, that's the best of both options.

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

21 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

Related Questions

Array.Push() for Vector3[] or how to add items to Vector3 array without knowing index 1 Answer

What is the order/connection of array elements in mesh.vertices? 2 Answers

c# : Accessing Struct variables inside an Array 1 Answer

Read variable from txt to Vector3 1 Answer

Vector3 Position returns 0 when applied to GameObject 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