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 /
avatar image
2
Question by aamesxdavid · May 01, 2013 at 02:29 AM · prefabrevert

Can you revert a prefab in-game?

I have my character set up as a prefab, and right now, I am re-instantiating it every time you die (because I'm changing a lot of things inside the character upon death). But this is leading to a lot of problems with lost connections that I have to repair by re-finding the character object in scripts that need to access it. This could all be made much simpler by a function like RevertPrefabInstance, but that works in-game, rather than just in the editor. Does this exist?

Comment
Add comment · Show 8
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 Loius · May 01, 2013 at 03:18 AM 0
Share

Not as such, but you could wire up a way to store the player's prefab in the player class, and in OnEnable, read the data back in from the prefab.

avatar image trs9556 · May 01, 2013 at 03:19 AM 0
Share

I don't understand what you mean by revert it? Just revert it back to the default prefab settings, before anything has potentially been changed? If that is what you mean, I don't understand how that would be any different from just instantiating a new one.

avatar image aamesxdavid · May 01, 2013 at 04:04 AM 0
Share

I have it instantiating a new object now, but it's the player object, so other scripts need to access it, like the camera to follow it. This means that whenever a new one is created, those scripts have to re-find the player object, searching through all of the objects in the scene, just to link the player object back up. Loius, I'm not sure exactly what you're suggesting, but this isn't just once the component is enabled, it's at any point in the game after the player dies, to put all of the pieces back in place. But it's way too complex a character to write up a script to reassemble it. I just want to not have to destroy the game object, and ins$$anonymous$$d replace it with a fresh prefab.

avatar image whydoidoit · May 01, 2013 at 04:55 AM 0
Share

You are probably better off using a Singleton pattern on your player - then nothing has to search to find it. They can do Player.instance and there it is. What language do you use?

Singleton Pattern:

  • Declare a static variable of the type of script, call it something sensible like instance or current

  • Set it to this during Awake()

  • Clear it during OnDestroy if it's still set to this

avatar image Fattie · May 01, 2013 at 06:38 AM 0
Share

The fundamental problem here, I think, is that you don't Instantiate in video games.

These days I mainly live to promote my answer regarding pools so here's the link ..

http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html

Also regarding prefabs. I feel it's well worth pointing out: there is absolutely no reason you have to use prefabs. For example FWIW in my co. we just don't like them and never use them for any reason, anywhere. So just don't panic about prefabs.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by SubatomicHero · May 03, 2013 at 08:28 AM

You could always enable or disable the gameobject rather than destroying and re-instantiating the object, it's what I do in my projects.

i.e once an object is instantiated instead of destroy you can use:

Gameobject.SetActive = false;

then respawning is true

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 afra-frantic · Aug 12, 2017 at 06:38 AM

I think this link will be useful: https://docs.unity3d.com/ScriptReference/PrefabUtility.ResetToPrefabState.html

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 tanoshimi · Aug 12, 2017 at 07:29 AM 0
Share

It's not - PrefabUtility is part of the UnityEditor namespace - the OP specifically states they want to do this in-game.

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

18 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

Related Questions

Why prefab revert does not work for position and rotation? 1 Answer

Reverting an object with children to its original prefab-state on runtime. 0 Answers

How do I reset a script's values at run time to what they were at start? 3 Answers

Why unity applies prefab position to my reverted gameobject ? 0 Answers

Reverting to prefab-state several game objects at once with stock Unity 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