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 FizixMan · Jun 16, 2010 at 04:58 PM · prefabsruntimecreate

Creating new prefab at runtime

Hi, my company is developing a viewer that will download meshes from the Interwebs at runtime and populate a scene using multiple instances of those meshes. It seems to me the process flow would be something along the lines of:

  1. Download mesh information
  2. Create new Prefab object
  3. Parse downloaded mesh information and build a Mesh object and assign it to the newly created Prefab
  4. Instantiate multiple copies of the prefab and move them around the scene.

Now we've managed to do steps 1, 3, and 4. But for step 2, we're using a prefab we've previously created in the Unity editor (it's just an empty box) at compile time. Our application won't know the number of custom prefabs that will be loaded, so I don't think it makes sense to create a finite number of prefabs in the editor at compile time. Is it possible to create a new Prefab from scratch from C# scripts? I've looked around but all the resources I've found are regarding creating Prefabs in the editor at compile time. Thanks for your time and 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

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

Answer by Mike 3 · Jun 16, 2010 at 05:07 PM

You wouldn't be creating prefabs, you can just create new gameobjects and add the necessary components to them

example in c#:

GameObject go = new GameObject("Bob");
MeshFilter filter = go.AddComponent<MeshFilter>();
MeshRenderer renderer = go.AddComponent<MeshRenderer>();
filter.mesh = yourMesh;

You can then Instantiate that object over and over if you like, as if it were a prefab

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 FizixMan · Jun 16, 2010 at 07:51 PM 0
Share

Thanks for the quick response. I got that working fine.

We still have yet to load in our complex meshes (doing test with single triangles), but from the performance perspective, I'm assu$$anonymous$$g prefabs have some optimizations with regards to handling all the instances of it. Our application will be making hundreds, potentially thousands of copies of the same object. Will this method without prefabs still perform well, or am I just mistaken? Thanks again for the quick response.

avatar image Mike 3 · Jun 16, 2010 at 08:34 PM 0
Share

It should work just the same - it uses the same object clone methods internally either way

avatar image FizixMan · Jun 16, 2010 at 08:57 PM 0
Share

Alright, thanks for the insight. Cheers!

avatar image jose senra · Aug 20, 2010 at 03:56 PM 0
Share

Hi all...

This seems excatly what I need for a project. I have to load potentially thousands of references to .FBX files stored in X$$anonymous$$L files and use them to call the objects from the project's interface.

Users will then choose the objects they want to load and they must be dynamically loaded. Could you confirm if this could be a way of doing so?

$$anonymous$$any many thanks.

Jose

avatar image ddan · Dec 04, 2012 at 02:56 AM 0
Share

Hi all

I also want to create a prefab at runtime. Specifically, I want to make a tool for converting assets that I've built into prefabs which I can later load remotely.

What I'm actually trying to do it save constructed assets as assetBundles, which says it needs prefabs. Doing this through the editor is not an option because it needs to be completely scripted/automated.

Thanks.

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

2 People are following this question.

avatar image avatar image

Related Questions

create 3d model at runtime 1 Answer

assign ui panel to a prefab object ? 2 Answers

Creating and saving prefabs during runtime 0 Answers

snapping objects at runtime 2 Answers

Delete all prefabs 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