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 /
avatar image
2
Question by Jeston · Jun 06, 2011 at 06:53 PM · transformreset

Reset Object

Is there a more stream lined way of doing an object reset or state restore ?

I am tired of writing the original position / original scale / original rotation in the onstart, and having a custom script on hundreds of objects just to reset them as they were when the level started.

Does anyone have a better strategy or is this the way to go ? It would be nice if the full transform had a setter for the transform.

At least then its 1 struct as opposed to 3 to have to set

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 syclamoth · Oct 31, 2011 at 03:17 AM 0
Share

Well, you could always write a 'copy' extension method for Transform...

avatar image rad1c · Mar 01, 2016 at 02:45 PM 0
Share

PrefabUtility.ResetToPrefabState()

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by sneftel · Jun 06, 2011 at 07:46 PM

You can use Application.LoadLevel() to reload the scene in its original state.

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

Answer by GoSuNeem · Oct 31, 2011 at 04:21 AM

If you are ok with reloading the level just do what Ben 12 said.

Otherwise, could just have 3 vec3s and store their own default positions.

 private Vector3 defPos;
 private Vector3 defRot;
 private Vector3 defScale;
 
 void Start()
 {
   defPos = transform.position;
   defRot = transform.localRotation;
   defScale = transform.localScale;
 }
 
 public void Reset()
 {
   //Reset them back
 }

That's the most simplest way imo.

Edit: Assuming if they are already placed in the world.

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 watchoutfree · Oct 10, 2012 at 09:45 AM 0
Share

If you have several arrayed object, in different arrays, you are not storing their default values in this Start function,Aren't you? In this case you are just storing the last one.

avatar image
0

Answer by bergarox · Oct 31, 2011 at 03:14 AM

need to know that too T_T

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

Answer by syclamoth · Oct 31, 2011 at 04:46 AM

Just putting this out there-

 public static void Apply(this Transform target, Transform original)
 {
     target.parent = original.parent.
     target.position = original.position;
     target.localScale = original.localScale;
     target.rotation = original.rotation;
 }

C# only, unless there's some way of doing this in JS. Basically you call it using

 transform.Apply(some other transform);

and it'll set all of your transform's values to that of the other one.

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

7 People are following this question.

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

Related Questions

how to reset a transform.rotate 1 Answer

Resetting a gameobjects position? 1 Answer

switch controlling transform 0 Answers

Rest Rotation Constraint 1 Answer

How to reset GameObject to original scale 2 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