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 /
This question was closed Jul 19, 2011 at 09:42 PM by G_Sacristan for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by G_Sacristan · Jul 16, 2011 at 08:46 PM · prefabsave

create prefab via script (JS)

Hi!

Ive tried many times, but i get errors and cant solve problem - create prefab from a gameObject.

Can someone help me out?

Here i add some gameObjects to a GameObject as children and after that i need to make a prefab out of that parent... I ve already tried

 //add children snippet
 modelShapes.objectSet[modelShapes.currentIdx].transform.parent=transform;
 hairObjects.objectSet[hairObjects.currentIdx].transform.parent=transform;
 
 //add prefab snippet
 function MakePrefab() 
 {
 var prefab : Object = EditorUtility.CreateEmptyPrefab ("Assets/createdPrefab.prefab");
 EditorUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
 }

Thanks in advance! I guess it should also help other people, who are searching for solution to this problem.

Comment
Add comment · Show 9
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 G_Sacristan · Jul 17, 2011 at 11:18 AM 0
Share

any ideas?

avatar image Marnix · Jul 17, 2011 at 11:19 AM 0
Share

So you want to DEFINE a prefab as if you would do it in javascript. Or do you want to instance a gameObject in your world?

avatar image G_Sacristan · Jul 17, 2011 at 11:38 AM 0
Share

I dont want to instantiate a prefab in world

i want to define a prefab and add gameObject to it, so i can use it later.

avatar image Bunny83 · Jul 17, 2011 at 12:07 PM 2
Share

You can't use UnityEditor functions in a $$anonymous$$onoBehaviour script. Well, you can but you won't be able to create a build of your game. You need to place the script in an folder called "editor" and make sure you import the UnityEditor namespace. Use either the Selection class to access the desired GameObjects or create an EditorWindow / wizard.

Prefabs are an Editor only feature (at least until now). In the runtime the prefab information is gone.

Errors are not "blah blah". $$anonymous$$ost of time they tell you exactly what's wrong, you just have to read it carefully and if you don't understand it at least copy&paste it here.

avatar image G_Sacristan · Jul 17, 2011 at 12:19 PM 1
Share

with Blah Blah i meant that there is more text that i cant remember right now - not that its useless!

So if i solved the problem then it means that only works in Editor, not Game itself? If yes... How can then i save an Avatar - Ive made my AvatarCustomization system

Show more comments

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Waz · Jul 17, 2011 at 12:31 PM

At runtime (which you seem to be talking about), a prefab is just the same as any other inactive GameObject. If you're talking about runtime, this is a no-op.

As to saving, you need to do that yourself at runtime. Search here for "save load" and you'll get heap of advice on that part.

Comment
Add comment · Show 2 · 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 G_Sacristan · Jul 17, 2011 at 12:32 PM 0
Share

I thought i could make a prefab and later in another Scene instantiate it if I need to.

avatar image Waz · Jul 17, 2011 at 12:36 PM 1
Share

You don't need to do anything special to do that. Provided the GameObject is marked DontDeleteOnLoad it will be there and you can Instantiate it to make a copy.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

List or Array of Custom Classes not saving into prefabs properly? 2 Answers

prefab when dragged on scene is not where its saved to be 1 Answer

How to save generated objects? 2 Answers

Avoid altering prefab at runtime 1 Answer

Creating/Saving prefabs during runtime? 7 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