Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
0
Question by satyam1507 · Sep 16, 2020 at 10:33 AM · gameobjectsprefab changing at runtime

How to convert gameobject into prefab at runtime?

I am trying to convert a gameobject into a prefab to a specific folder using code. Basically, when the user hits the done button, a gameobject should be converted into a prefab to a specific folder from where those prefabs will be sent to firebase storage. I didn't find any way to do it. Is it even possible?

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

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

Answer by N-8-D-e-v · Sep 16, 2020 at 11:37 AM

It is indeed, impossible, BUT there is a pretty simple workaround. Say you want to create a prefab at runtime of skyscraper B. Save a prefab of Skyscraper A, then put one in your scene, and set it to inactive. Then, edit that object at runtime, and just instantiate whenever, so it acts like a prefab.

Comment
Add comment · Show 7 · 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 satyam1507 · Sep 16, 2020 at 12:01 PM 0
Share

Thanks for your reply N8. The solution you have given can't be applied in my game. But I have found a way to do it with the help of editor script. PrefabUtility.SaveAsPrefabAsset();

avatar image N-8-D-e-v satyam1507 · Sep 16, 2020 at 08:58 PM 0
Share

awesome, glad it worked out!

avatar image Bunny83 satyam1507 · Sep 17, 2020 at 12:38 AM 0
Share

But you said you want to do this at "runtime" and that "users" should be able to do this. Editor scripts only work inside the Unity editor. So your usecase is quite confusing. Prefabs are editor only features. They do not exist at runtime. Prefabs are just predefined objects that are not part of the scene and can be used as cloning source.

avatar image satyam1507 Bunny83 · Sep 17, 2020 at 02:52 AM 0
Share

You are right. Why I didn't thought about that. I am new to editor script. I think I need to find some other way to solve my problem.

Show more comments
avatar image
1

Answer by Liamono · Sep 21, 2020 at 05:21 PM

The best way to do this is to set up a custom save system that uses .bin, .json, or .txt files. You'll need to have a script that can create a .bin, .json, or .txt file on disk, and then have the GameObjects re-construct themselves upon instantiation (via Start(), Awake(), etc) using the custom file. There's no way to save a prefab directly in a built game, but using .bin/.json/.txt allows you to achieve the same effect for almost any aspect of any game.

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

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

Reinitialize prefab 0 Answers

Multiple Prefab in Object Pool or One Prefab With Add Component 0 Answers

Setting Vector3.angle between two gameObjects 2 Answers

How to make only this red area clickable on the cube ? 0 Answers

Position gameObjects in circle around another gameObject 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