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 COLLAnitySV · Jan 12, 2012 at 09:55 AM · arrayvector3playerprefsfor-loopplayerprefsx

assigning arrays with for in

hi, i have a problem with assigning arrays with for in loops. I'm going to make PlayerPrefsX.SetVector3Array with this. How to make it saves / assign the Arrays of Vector3 in RegSaver Vector3 arrays (which saves the arrays) ? But, when i'm trying to make the for(var om in rs.objPos) transform.position = om; and yea it's really does working but when i check the RegSaver arrays, all values of Vector3 were same. You know what i mean right ? Please. thanks for the read

this is my script. (objects.js) rs is RegSaver;

     if(PlayerPrefs.HasKey("plx")){
             positions = PlayerPrefsX.GetVector3Array("plx");
             for(var om in rs.objPos){
                 transform.position = om;
             }
         }
     function Update () {
     if(Input.GetKeyDown("b")) SaveExitGame();
     for(var om in rs.objPos){
         om = transform.position;
     }
 }

and RegSaver.js

 var objPos : Vector3[];
 var usedObj : boolean[];
 
 function Update(){
     if(Input.GetKeyDown("p")){
         SaveThisPrg();
     }
 }
 
 function LoadThisPrg(){
     objPos = PlayerPrefsX.GetVector3Array("plx");
     usedObj = PlayerPrefsX.GetBoolArray("pbx");
 }
 
 function SaveThisPrg () {
     PlayerPrefsX.SetVector3Array("plx",objPos);
 }
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 Kryptos · Jan 12, 2012 at 10:22 AM 1
Share

What I don't understand is why you are saving an array of Vector3, when you only need one Vector3 to store/retrieve the position ?

avatar image COLLAnitySV · Jan 12, 2012 at 01:40 PM 0
Share

it's for saving the game objects location when the Application Quit...

avatar image syclamoth · Jan 12, 2012 at 02:24 PM 0
Share

Right. As explained in my post, that's really not what you're doing in that script there.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by syclamoth · Jan 12, 2012 at 10:22 AM

Well, this is all very well- but what do you really expect?

 transform.position;

will always return one value, and by the looks of things you are iterating through an array and setting every single member of the array to the same thing! If you look at the Update function, you'll see that every single frame you overwrite the entire array with a single value. Why do you expect transform.position to return something different in every iteration?

Of course, even the other end of the system is flawed. When you read the values back out again, even if the array has a lot of different values in it, only the last one will make any difference! Because you're setting 'transform.position', none of the previous iterations will be remembered outside of the loop! Only the last one actually matters.

So, unless there's something you're not telling us about what this script is supposed to do, I'm not really sure how you could expect it to do anything different!

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

6 People are following this question.

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

Related Questions

For In Loop Fills all values in arrays problem 2 Answers

How to save rotation with PlayerPrefsX? 1 Answer

PlayerPrefsX plugin error when build for windows store 3 Answers

Attempting to store an Inventory Array in PlayerPrefsX 1 Answer

Why is this giving me an error? (ToBuiltin problems) 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