• 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 wyatts · Jul 25, 2017 at 11:42 PM · transformlistlistsfor-loopfor

List of Transforms updating all items when adding variable.

I'm attempting to create a list of Transforms filled from a variable that changes every FixedUpdate:

 IEnumerator FillList(){
     for (int i = 0; i < listItems; i++) {
         transformList.Add(newTransform);
         yield return new WaitForFixedUpdate();
     }
 }

The variable "newTransform" is changing every FixedUpdate, but when I fill the list it fills every item on the list with the same value, instead of adding the new updated value and keeping the old ones.

Any ideas on how to add a new value every loop?

I've also tried

 transformList.Insert(i, newTransform);

I've tried both using a struct and a separate class to do somet$$anonymous$$ng like:

 transformList.Add(new TranPositions(newTransform));

Yet I keep getting the same results. Any help would be greatly appreciated! Thank you!

Comment
Add comment · Show 2
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 NoseKills · Jul 26, 2017 at 06:15 AM 0
Share

The list will surely get the object newTransform holds at the time of calling Add(). So my guess is the problem isn't in the shown code but in how and where newTransform is assigned values to or such.

avatar image wyatts NoseKills · Jul 26, 2017 at 08:27 PM 0
Share
Hey @NoseKills thanks for the reply. It does get the object at the time of calling Add() -- it just changes EVERY value in the list with the latest object. Any idea why they would all change like that? I'll work on making a simple version of the problem.

1 Reply

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

Answer by · Jul 26, 2017 at 08:41 PM

From what I can tell, you are saving a transform reference. When you save a transform, you don't save the values of the transform, you save a reference for that transform. Try saving only the information that you need (ex: Vector 3 transform.position, Quaternion transform.rotation, Vector 3 transform.scale).

Comment
Add comment · Show 2 · 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 wyatts · Jul 28, 2017 at 12:13 AM 0
Share

A TRUE HERO. This is the kind of information I have a hard time finding! Thank you so much for the help. When I chose a specific element (in this case newTransform.rotation) everything worked as it should.

avatar image wyatts · Jul 28, 2017 at 01:31 PM 0
Share

Glad I could help :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

82 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

Related Questions

Copy values between two classes in two lists. 1 Answer

A node in a childnode? 1 Answer

child not set to parent while in for loop 1 Answer

Affect every object in array. 1 Answer

Sorting a list into multiple smaller lists 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