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 /
  • Help Room /
avatar image
0
Question by unity_ojMrm1iuJKQ-dw · Oct 16, 2017 at 05:59 PM · prefabimportblender

Instantiate a prefab of a Blender model w/ Behavior that supports changes to model

(This is not a question, but an explanation of a solution to a problem I've been facing. I'm curious if this is the optimal way to solve what I expect to be a near ubiquitous need, namely...)

Goal

Be able to instantiate a Prefab programatically that has a RigidBody, possibly some behavior (e.g., an arrow in flight, a rock, an enemy) whose model was developed in Blender such that whenever the model is changed there is zero work required to update the project... just save in Blender, and click play and the game is using the new model.

Addressing the above goal has proven to be surprisingly difficult to do, so I wanted to post to make sure that I'm not missing something obvious, and share what I've found.

Solution

  1. Create project folders "Resources/Blender" and "Resources/Prefabs".

  2. Save Blender model in "Resources/Blender".

  3. Tweak Materials of imported object in Unity since loader doesn't do this automatically.

  4. Create an Empty Object, and attach RigidBody, behaviors etc (but not the model), Reset transform etc.

  5. Create Prefab from the Empty Object into "Resources/Prefabs", and give it a similar name to the model.

With that done, to create the object at runtime, "Instantiate" by name each part, and then make the "EmptyObject" version the parent of the model, reposition etc. Arrows fly, objects get dropped, monsters spawn. When the model is updated in blender, just save and play, and even the materials stay applied (though unsure why that works so well).

C# sample:

 GameObject obj = (GameObject)Instantiate(Resources.Load("Prefabs/arrow"));
 GameObject arrowBlend = (GameObject)Instantiate(Resources.Load("Blender/arrow"));
 arrowBlend.transform.parent = obj.transform;  // linked!
 Rigidbody arrowRigid = obj.GetComponent<Rigidbody>();
 Vector3 startOffset = transform.rotation * new Vector3(0, 0, 1.5f);
 arrowRigid.position = transform.position + startOffset;
 // etc...

I recommend preloading the Resources and storing references etc.

Comments

Given how frequently dynamic objects are used in games, I'm surprised with how much effort it was to get this setup in a stable, reimportable way. I'm hoping there is something obvious I missed in Unity. I tried a number of different thing like creating a prefab of my model, but that seems to fix the model at the time of prefabing, rather than have a prefab that links to the model's name (prefab of a prefab is a no go).

Also, putting all the runtime addressable entities into "Resources" folder seems quirky. Perhaps there are projects out there with large numbers of objects that don't get built into the game, but in my game that won't be the case. Many programming languages cull unreferenced compiled code at link time, but support an "alwayslink" pragma or equivalent; maybe Unity could use a bool flag on each project entities so to force it to be addressable?

I'm having a lot of fun teaching my kids about programming, games, and modelling w/ Unity. Thanks all!

JJ

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

0 Replies

· Add your reply
  • Sort: 

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

154 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix this cube ? 1 Answer

Imported Models Not Rendering Correctly? 5 Answers

Normal map seams 0 Answers

Blender to Unity armature not in correct place... 1 Answer

Can faces be made visable from both sides on assets from blender. 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