Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
3
Question by Mediahaze · Apr 07, 2010 at 12:59 PM · scenecomponentreset

Reseting Component/GameObject to its initial scene state.

I would like to create a basic behaviour for my components that lets them be reset to the original values at the begining of the scene when they are complete. In otherwords, I want a simple way to create 'Repeat on Complete' functionality. Without reloading the scene or instantiating a prefab, is there a way to reset an object/component to its original scene state?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by duck · Apr 07, 2010 at 02:12 PM

I don't think there's a built-in way, but you could implement this yourself by storing the values that you'd like to be re-set in the Start function. Eg:

var originalPosition : Vector3; var originalRotation : Quaternion;

function Start() { originalPosition = transform.position; originalRotation = transform.rotation; }

function Reset() { transform.position = originalPosition; transform.rotation = originalRotation; if (rigidbody != null) { rigidbody.velocity = Vector3.zero; rigidbody.angularVelocity = Vector3.zero; } }

If you wanted to re-set other values such as animation state, visibility, etc, you'd have to add each of these as separate variables, with the corresponding lines of code to reset them.

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
-1

Answer by lassade · Aug 13, 2013 at 07:52 PM

Make your object an prefab and try

UnityEditor.PrefabUtility.ResetToPrefabState(this.gameObject)

It not seems to work for me though, but the docs says "Resets the properties of the component or game object to the parent prefab 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
-1

Answer by sathya _m · Nov 04, 2013 at 07:40 AM

//read all game objects and set initial position when ever it needs

in c#

 private Dictionary<GameObject,Vector3> current_obj_trans_value = new Dictionary<GameObject,Vector3>();


 public void intial_pos_set()
  {

    object[] allObjects = FindObjectsOfTypeAll(typeof(GameObject)) ;


    foreach(object thisObject in allObjects)
  {
     if (((GameObject) thisObject).activeInHierarchy &&((GameObject) 


         thisObject).GetComponent() != null)
         
           current_obj_trans_value[((GameObject)thisObject)]=
                                       ((GameObject)thisObject).transform.position;
 
  }
   
  }




public void reset_tranform_pos() {

     foreach(KeyValuePair<GameObject,Vector3> allactobj in 

                                                    current_obj_trans_value)
     {
     
         allactobj.Key.transform.position= allactobj.Value;
               
         }

  }
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 MihaMarn · Jun 16, 2021 at 01:53 PM

Create an object prefab with desired properties. In-game instantiate this prefab. Change those properties however you like. When you need to set defaults, simply destroy this game object and instantiate a new one from the prefab. Now, this new one will have all props set to default. If you want to change some of those, simply adjust them just before instantiation.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Unity 3d(Space) Questions 1 Answer

Scene changing 1 Answer

Adding joints through script 2 Answers

Reset The Scene ? 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