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 /
avatar image
0
Question by uzairf · Nov 22, 2017 at 01:47 PM · c#runtimeexportunitypackage

Export unity-package on Run time?

Hi, I want to export a game object made on runtime using c# scripting. Mainly I want that a game object may be a cube to be made on runtime and then that game object to be exported as a unity package by simple some button click but I want this to happen on runtime[editor / in playmode]. May this can be done using Reflection? Please help me out.

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
2
Best Answer

Answer by Grish_tad · Nov 23, 2017 at 12:10 PM

Just call createUnityPackage() function, when button is clicked. Script will create unitypackage from all files included in "Assets/Prefabs/" folder and save it in "Assets/" folder with gameobject name. You can modify script for your use.

     using UnityEngine;
     using System.Collections;
     using System.Collections.Generic;
     using System;
     using System.IO;
     using UnityEditor;
     
     public class UnityPackager : MonoBehaviour {
     public static void createUnityPackage()
         {
             GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); 
     
              Instantiate(obj, new Vector3(0, 0, 0), Quaternion.identity);
             string filePath = "Assets/Prefabs/";
             FileInfo file = new FileInfo(filePath);
             file.Directory.Create();
     
             string  prefabfilename = filePath + obj.name + ".prefab";
             UnityEngine.Object prefab = PrefabUtility.CreateEmptyPrefab(prefabfilename);
     
             PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ConnectToPrefab);
     
             string exportPath = "Assets/" + obj.name + ".unitypackage";
             
             AssetDatabase.ExportPackage(prefabfilename, exportPath, 
            ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Recurse);
       
     
         }
     }




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 uzairf · Nov 24, 2017 at 04:52 AM 0
Share

Thanks a lot it worked for me :)

avatar image giantkilleroverunity3d · Jan 27, 2019 at 08:05 PM 0
Share

This worked perfectly. See my answer below about the future. I am still 2018.2.2f1 and can not afford to update at the moment

avatar image
0

Answer by giantkilleroverunity3d · Jan 27, 2019 at 07:47 PM

@Grish_tad @uzairf But not in 2018.3: deprecated. Now you must find another way. I am looking into runtime creation of asset bundles.

Comment
Add comment · Show 5 · 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 giantkilleroverunity3d · Jan 31, 2019 at 09:08 PM 0
Share

I also found that after i disable scripts on child objects the child object scripts are enabled when I pull the large prefab back into the hierarchy. But during the previous play mode the scripts are disabled. So the setting is getting reversed.

avatar image fraeri · Feb 04, 2019 at 02:34 PM 0
Share

Do you found a solution for the runtime creation of asset Bundles? $$anonymous$$y Project lets you import a obj and I need to "share" it with all other clients of the Project. So somehow the "Importer" needs to upload the gameobject and the rest needs to download it somehow.

avatar image giantkilleroverunity3d fraeri · Feb 04, 2019 at 04:23 PM 0
Share

@fraeri During runtime I drag the newly generated gameobject to the assets/prefab folder. This definately saved the correct state of the GO. Later I can drag that into the hierarchy. Runtime import is a step I have to do next.

avatar image fraeri giantkilleroverunity3d · Feb 04, 2019 at 07:40 PM 0
Share

@giantkilleroverunity3d - nice, but that is not an option for me because the user creates the GO during runtime outside of Unity. Got any ideas for the next step? $$anonymous$$aybe we can solve it together

Show more comments

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

74 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Export objects to a .3DS file at runtime 1 Answer

Export cad formats from unity3d 0 Answers

How to export an fbx file with assimp that can be used in Unity? 0 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