Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by erikiene · Nov 17, 2016 at 02:53 PM · unity 5arraysarray of gameobjectsarraylistrewind

Problems with arrays (or how to rewind objects' states)

Hi all,

I'm implementing a mechanic where when triggered, target objects would rewind to their initial positions/rotations/etc. The problematic part of this currently looks something like:

     ArrayList Movements = new ArrayList();
     ArrayList Rotations = new ArrayList();
     public GameObject[] targets;
 
 (in update:)
 
             for (int i = targets.Length-1; i >= 0 ; i--)
             {
                 Movements.Add(targets[i].transform.position);
                 Rotations.Add(targets[i].transform.rotation);
             }
 
 (coroutine to rewind:)
 
             for(int i = 0; i<targets.Length; i++)
             {
                 targets[i].transform.position = (Vector3)Movements[MovementIndex];
                 Movements.RemoveAt(MovementIndex);
                 targets[i].transform.rotation = (Quaternion)Rotations[MovementIndex];
                 Rotations.RemoveAt(MovementIndex);
             }
             yield return new WaitForSeconds(0f);
 

I think I've pasted in all the relevant parts for solving what's wrong. Basically, it worked well for just one target, e.g. player, but I want to implement an open array defined in the editor (GameObject[] targets) so I can apply the rewind to any object I want. So when I went and tried it with a player and the camera, it, for some reason (possibly my lack of understand how these arrays are called), it looks like the camera jumps around as if it's using all of the positions and rotations recorded, not just the ones captured from the camera transform. I played around with order of execution in the "for" functions but to no avail..

Any ideas?

Additionally, if anyone has a suggestion on how to implement the captured parameters in a single multi-dimensional array, please share, I couldn't wrap my head around that either. Something like [(player.position1, player.rotation1),(cam.pos1, cam.rot1),....] but that'd be there just to make it neat so is not as important.

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 hexagonius · Nov 17, 2016 at 10:59 PM 0
Share

you shouldn't have one script with all the targets but this one script on each target. that way every target has it's own arrays and won't iterate all values that have been added (what you're doing right now)
you should also not remove entities during iteration because that reduces the amount of data by half and you skip every second value.
for bundling up the data you need you could create a struct of the values you're saving. they would make the ArrayLists just one consisting of instances of one struct with all the different values saved each frame.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

How to compare a position of an object within an array 1 Answer

C# ArrayList Accessing and RemoveAt? 0 Answers

Assigning a different material to different objects 2 Answers

Pass array through text field of game objects,Pass array throug multiple Text fields 0 Answers

How to play a random audio clip from an array in C#? 3 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