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 /
This question was closed Jun 12, 2015 at 07:52 AM by DiebeImDunkeln for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DiebeImDunkeln · Jun 11, 2015 at 01:01 PM · transformscenenull

why a list of transforms is empty after loading new scene?

I have a settings class with a static list filled with Transforms. If I load a new scene and try to get one of the items from the list, all entries are set to NULL.

Is there a reason why Unity can't keep Transforms in a List from one scene to another?

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

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by dubbreak · Jun 11, 2015 at 07:55 PM

Because the Transforms are by reference not by value. When a new scene loads they all end up null (assuming the Transforms are of scene objects).

If you want to keep them around you either need to make copies of the Transforms to put in your list (which not change when the original transform changes) or use Vector3 or some other datatype to store them statically (updating periodically).

If you are familiar with pointers (and not with references), it's essentially your list is a list of pointers to Transforms (that are owned by the object). When that object goes away that memory location is now null (because of the object destructor). Not 100% correct, since it's references, not pointers.. but the key point is you don't have copies of the Transforms, your list just points to the existing ones and when the object with that transform goes away the transform gets nulled.

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 DiebeImDunkeln · Jun 12, 2015 at 06:24 AM 0
Share

Thank you for that detailed explanation. :)

avatar image dubbreak · Jun 12, 2015 at 02:02 PM 0
Share

Glad I could help.

avatar image
1

Answer by Notter · Jun 11, 2015 at 01:08 PM

If you want to keep GameObjects persistent across scene transitions, you need to have a script on them with:

  DontDestroyOnLoad();

I'm taking a guess that your script with the list, is not persistent. but you need yo give more information on your script and what exactly are you doing

Comment
Add comment · Show 1 · 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 DiebeImDunkeln · Jun 11, 2015 at 02:13 PM 0
Share

Problem is, DontDestroyOnLoad(this) keeps the Transforms also in the history but I don't need them in the next scene.

I my case I have a tile map of a museum and all tiles are stored in a list of transforms. Then it is possible to collect items by playing a $$anonymous$$igame in another scene and after this I come back to the museum.

The list of transforms is in a static settings class which is not bound to a gameobject. All infos (int, string etc.) keep alive when I switch the scenes, but only the transforms in the list get deleted. In my case I found a workaround. I don't really need the transforms at the moment, I only needed the x/y positions, so I made a helper class for the positions and store this in a list.

so my question is in general nature, thy transforms in lists get lost.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Changing the player's starting position depending on the scene transition. 1 Answer

How to move the world/scene not the player - or not? 1 Answer

Unity 3d(Space) Questions 1 Answer

How Do Camera Follow Mullti Playeres 2 Answers

Destroyed Objects causing errors (transform/setdestination) 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