• 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 /
  • Help Room /
This question was closed Dec 11, 2015 at 12:04 PM by Xamur for the following reason:

Andere

avatar image
0
Question by Xamur · Nov 09, 2015 at 11:14 AM · scripting problemprefabsaveparentchild

How to save as prefab when a button is pressed

Hello, I found this Thread but I did not found a good answer. I would like to create a button and if this button is pressed it should save the 2D created Character (<- 'Character' is an Empty GameObject with child Objects attached on it, like 'Arms', 'Legs', etc. and those have a spriteRenderer on them to select the different sprites) with all of its child objects as a prefab.

I have something like this:

 public void SaveCharacterAsPrefab() 
     {
         Transform.Instantiate Character
         int Character
         string prefabPath = "SavedCharacters";
         PrefabUtility.CreatePrefab("Assets/Resources/" + prefabPath + "/" + Character.name + ".prefab", Character, ReplacePrefabOptions.ReplaceNameBased);
     }


But (of course) it doesn't work because I don't know exactly how to 'tell the script' that it should save the Character with all of its child objects and (for example) name/save it as 'Character 1'. I don't know how I can solve it... Thanks for anyone who wants to help!

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

1 Reply

  • Sort: 
avatar image
0

Answer by OctoMan · Nov 09, 2015 at 11:50 AM

Read this, it might help you out. http://prof.johnpile.com/2014/07/27/generateprefab/

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 Xamur · Nov 09, 2015 at 09:49 PM 0
Share

Well, it's good but I cannot do a working script for my project on my own. I just don't know how to change/add things to some of those scripts so it's working for me, too... :(

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I make character pick up object to front of him? 1 Answer

Set parent of an object when they collide? 2 Answers

How do I spawn an array of prefab clones as children of an object? 1 Answer

Why does importing a mesh create a parent. 0 Answers

how add child to multi gameobject 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges