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 POLYGAMe · Feb 04, 2012 at 11:02 PM · aiarrayssave datawaypoints

Saving Vector2 coordinates as waypoints to dynamic array

Hi there,

I am wanting to write a script that allows me to control my player car and every half second or so, store the X/Y coordinates to an array, increasing the size of the array as it does so. Then I can use the data stored in the array as waypoints for my AI cars to drive between (can also use it as ghost data).

I understand how to set up arrays and add the data to them, the question I have is... how do I make it so that I can access that data inside the array and store it for use with another car without being zeroed every time I run the scene?

Would I need to save the data to an external file and then read it back in? I'm a bit of a Unity/game dev noob, so this stuff seems a little tricky to me but once I have the "idea" of how to do it, I should be able to work it out. I'm not asking for scripts or code samples.

The only way I could make it work right now would be to print the values to the debug console and manually go through them and add them to the AI script by hand... that seems silly. LOL.

Any help would be greatly appreciated ;-)

Comment
Add comment · Show 1
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 POLYGAMe · Feb 04, 2012 at 11:04 PM 0
Share

Hmm... that was long-winded... in a nutshell... how do I add values to an array and keep them without being zeroed on next run? Cheers :)

1 Reply

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

Answer by Berenger · Feb 04, 2012 at 11:17 PM

You can use playerprefs to do that. Unfortunately, there isn't a Get/SetArray, so you can use this instead. (From Eric5h5)

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 POLYGAMe · Feb 04, 2012 at 11:22 PM 0
Share

Thanks! Can I just set the array in one script to equal the array from another script, as you can with simple variables?

avatar image Berenger · Feb 04, 2012 at 11:26 PM 1
Share

Oh, I thought you had to change the entire scene ! Well yes, you can totally do (Edit)

 int[] array1= { 0, 1, 2 };
 int[] array2= new int[ array1.Length ];
 System.Array.Copy(array1, array2, array1.Length);
avatar image POLYGAMe · Feb 04, 2012 at 11:27 PM 0
Share

Ah, no, sorry... not changing scenes! Cool, that makes it simpler. I'll just need to work out playerprefs now. LOL.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot save(serialize) a double array of a custom class 1 Answer

Why is everything being set the same? Please Help! 1 Answer

Follow up to AI Pathfinding Question 0 Answers

how to instantiate gameobjects in a 2d array. 2 Answers

How how can I make AI only move towards objects that are active in the scene 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