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 user-4347 (google) · Oct 07, 2010 at 10:32 PM · gameobjectprefabcreate

How to create and save a gameobject to a prefab with a script

I want to know how to create an empty prefab and in that prefab put the gameObject. But I dont need the page were you find that I actually know is http://unity3d.com/support/documentation/ScriptReference/EditorUtility.CreateEmptyPrefab.html to create a prefab and http://unity3d.com/support/documentation/ScriptReference/EditorUtility.ReplacePrefab.html to put the gameObject to a prefab but I dont understand it to well so please, someone could write me how to do that in a script.

Thanks for future :)

Comment
Add comment · Show 1
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 drudiverse · Apr 02, 2014 at 10:36 AM 0
Share

class CreatePrefabFromSelected search it on google

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by · Oct 07, 2010 at 11:22 PM

Take a look at: How do I programmatically assign a GameObject to a prefab?

There is some code provided there (in C#), so hopefully you can gain an understanding from it.

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 BadPritt · Sep 02, 2014 at 03:05 PM 0
Share

http://answers.unity3d.com/questions/29471/how-to-create-and-save-a-gameobject-to-a-prefab-wi.html is the up-to-date url

avatar image intrepidis · Nov 19, 2014 at 01:55 AM 0
Share

Take a look here: http://answers.unity3d.com/questions/27626/how-to-create-prefabs-from-editor-scripts.html#answer-835388

avatar image
1

Answer by DoneDesign · Oct 25, 2010 at 02:10 AM

NOTE: THIS IS IN C#

You could always create one script called "SaveData" or something similar and have this in it

using UnityEngine; using System;

public class SaveData : MonoBehaviour {

 public void SaveCharacterData() {
     GameObject pc = GameObject.Find("pc");

     PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();
     PlayerPrefs.SetString("Player Name", pcClass.Name);

     for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
         PlayerPrefs.SetInt(((AttributeName)cnt).ToString() + " - Base Value", pcClass.GetPrimaryAttribute(cnt).BaseValue);
         PlayerPrefs.SetInt(((AttributeName)cnt).ToString() + " - Exp To Level", pcClass.GetPrimaryAttribute(cnt).ExpToLevel);
     }

     for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
         PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Base Value", pcClass.GetVital(cnt).BaseValue);
         PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Exp To Level", pcClass.GetVital(cnt).ExpToLevel);
         PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Current Value", pcClass.GetVital(cnt).CurValue);

// PlayerPrefs.SetString(((VitalName)cnt).ToString() + " - Mods", pcClass.GetVital(cnt).GetModifyingAttrituesString());

     }

     for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
         PlayerPrefs.SetInt(((SkillName)cnt).ToString() + " - Base Value", pcClass.GetSkill(cnt).BaseValue);
         PlayerPrefs.SetInt(((SkillName)cnt).ToString() + " - Exp To Level", pcClass.GetSkill(cnt).ExpToLevel);

// PlayerPrefs.SetString(((SkillName)cnt).ToString() + " - Mods", pcClass.GetSkill(cnt).GetModifyingAttrituesString());

     }
 }

 public void LoadCharacterData() {
     GameObject pc = GameObject.Find("pc");

     PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();
     pcClass.Name = PlayerPrefs.GetString("Player Name", "Name Me");

     for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
         pcClass.GetPrimaryAttribute(cnt).BaseValue = PlayerPrefs.GetInt(((AttributeName)cnt).ToString() + " - Base Value", 0);
         pcClass.GetPrimaryAttribute(cnt).ExpToLevel = PlayerPrefs.GetInt(((AttributeName)cnt).ToString() + " - Exp to Level", 0);
     }

     for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
         pcClass.GetVital(cnt).BaseValue = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Base Value", 0);
         pcClass.GetVital(cnt).ExpToLevel = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Exp to Level", 0);

     //make sure you call this so that the AdjustedBaseValue will be updated before you try to call to get the curValue
     pcClass.GetVital(cnt).Update();

     //get the started value for the curValue for each vital
     pcClass.GetVital(cnt).CurValue = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Cur Value", 1);
     }

     for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
         pcClass.GetSkill(cnt).BaseValue = PlayerPrefs.GetInt(((SkillName)cnt).ToString() + " - Base Value", 0);
         pcClass.GetSkill(cnt).ExpToLevel = PlayerPrefs.GetInt(((SkillName)cnt).ToString() + " - Exp To Level", 0);      
     }

     //output the curValue for each of the vitals
     for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
         Debug.Log(((SkillName)cnt).ToString() + ": " + pcClass.GetSkill(cnt).BaseValue + " - " + pcClass.GetSkill(cnt).ExpToLevel);
     }

} }

I apologize for all the stuff in there those are just what determines my skills/vitals... If you want to learn how to set up those check out the tutorial by BurgZergArcade on youtube...

Im not going to give you a link to his videos for two reasons...

  • It helps to start from the beginning of his tutorials to set this up...
  • You can just go to his channel which is BurgZergArcade.

I apologize if this doesn't help because of all you have to do to get it to work but i tried...

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 DoneDesign · Oct 25, 2010 at 02:23 AM 0
Share

you will get alot of errors if you don't follow the tutorial but basically all you have to do is have the voids for loading and saving you character and than have the PlayerPrefs.SetInt(((coding...

avatar image
-2

Answer by stringa · Oct 07, 2010 at 11:15 PM

I don't know if you can do that....

You can create a "base" prefab and append on any extra components needed.

Unity is not good at doing things that it wasn't designed to do...

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 · Oct 07, 2010 at 11:21 PM 1
Share

You absolutely can create prefabs and assign gameObjects to them via script.

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

1 Person is following this question.

avatar image

Related Questions

How could I create a prefab from an exsisting gameobject at runtime? 2 Answers

Two exact objects behaving differently... *scratches head* 0 Answers

Show and Hide a prefab or GameObject 10 Answers

How to restart a "prefab'd" level? ;) 0 Answers

Prefab (Project Folder) to a GameObject (on 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