x


How can I keep the prefab connection when re-export an fbx with added objects ?

I created a prefab and added functionality to it (scripts, colliders, rigidbody). After adding the components, I click "apply" to re-establish the prefab connection. But when I export an updated version of the fbx file that contains new objects, these do not show in Unity. If I drag the fbx onto the prefab, it gets overwritten and all added components disappear.

Is there a workaround or an asset post-processor script that can help out here ?

Seems to me that its a normal fact of life that during development objects get added. I can't believe that a workflow-oriented tool like Unity cannot handle this.

[edit]

To clarify my question, consider this workflow :

  • In max create a teapot
  • Export to teapot.fbx
  • Create empty GameObject
  • Drag the teapot into the hierarchy view as child of the GameObject
  • Add components to the GameObject and/or teapot
  • Create prefab
  • Drag GameObject onto prefab
  • In max add another teapot and re-export to teapot.fbx

The second teapot is not added to the prefab. What workflow allows me to update the teapot prefab and keep the existing components ?

more ▼

asked Dec 09 '09 at 02:20 PM

PatHightree gravatar image

PatHightree
379 7 10 20

"Add components to the GameObject and/or teapot" - and/or won't work here. As soon as you add components to the teapot, you break the prefab connection and are up for trouble. It's best to simply not change the model object at all and apply any changes "one level up" (see my answer below for more details). If you don't change "teapot.fbx" inside Unity, adding objects should work (unless there's some oddities with the FBX importer here).

Dec 10 '09 at 04:46 PM jashan

@Hightree, remember to upvote good answers also.

May 01 '10 at 02:38 PM Cyclops
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

In general, I wouldn't recommend directly adding models to the scene and modifying them (which does break the prefab connection and as you have experienced - that's not so easy to fix in this specific case).

Instead attach the models as child objects of empty game objects and attach any scripts and other components to this empty parent game object instead of to the model. That way, you can easily update your models without any problems. You can also create a Prefab from the parent object (and then use that instead of the actual model).

You can see the difference between a "model pseudo-prefab" and a "real prefab" by looking at the icon (it looks a little different).

You can easily access your "model game object" from the prefab ("parent game object") in scripts by adding a public GameObject member variable to those scripts. Like:

public GameObject model; // C#

var model : GameObject; // UnityScript

Then, all you need to do is drag the child object (which is your model) onto the slot in the property inspector of your script in the parent object (which is your prefab).

Another nice thing about this approach: You can easily extend this without breaking all your scenes, e.g. you could include different poly-versions of the same model and then dynamically show/hide the different versions (as needed), which would be the foundation either for your own custom LoD (Level of Distance) implementation, or could also be used to dynamically switch models with different complexities based on framerate.

If you use the models directly, and then at some later point in time decide you want to do something fancy, "conversion" might be extremely painful (been there, done that, got a T-shirt ;-) ).

more ▼

answered Dec 09 '09 at 03:02 PM

jashan gravatar image

jashan
10.1k 25 40 116

A very interesting approach, replacing geometry under a placeholder parent. However some components like colliders have to be put on the objects themselves, right ?

Dec 09 '09 at 10:54 PM PatHightree

Depends ... mesh colliders - yes. But those would be generated on import anyways, so they should be available in the "model object". Other colliders can just as well be attached to the parent object. I'm not sure about rigidbodies, though - that's where the approach may hit a limitation (if you have to use the rigidbody with the mesh collider of the imported model). You could probably also attach a mesh-collider to the parent object and then select the correct mesh - but I doubt that will give you the desired results.

Dec 10 '09 at 07:49 AM jashan

Attaching the rigidbody and mesh collider component with the correct mesh to the parent GO works just fine.

Dec 10 '09 at 09:26 AM AngryAnt ♦♦

Thanks for the clarification, Emil!

Dec 10 '09 at 04:43 PM jashan

Ok, that simplifies things. Seems like this might work out after all :) Thanks !

Dec 11 '09 at 05:11 PM PatHightree
(comments are locked)
10|3000 characters needed characters left

When you reexport your art, if the name of the mesh in the fbx hasn't changed, then your updates should be reflected without issue.

When you say that the prefab does not show in Unity, does that mean that the mesh disappears? If so, check the inspector. Does it say Mesh Filter [None], Missing (Mesh)? That means you've somehow confused Unity... maybe by changing the name of the mesh?

more ▼

answered Dec 09 '09 at 02:50 PM

Lance Sun gravatar image

Lance Sun
1k 12 16 41

(comments are locked)
10|3000 characters needed characters left

We have a similar problem, everytime my graphic update me with his new levels, we are in a nightmare, because ONLY if I copy HIS "assets/library" folder I get their level right, but this is not gonna play good, with my project library folder and my levels!

Is this perhaps somehow related to the internal importing library folder?

more ▼

answered Dec 10 '09 at 02:47 PM

Litobyte Softworks gravatar image

Litobyte Softworks
37 2 2 6

This is not really related to the question, please don't thread-hijack. Just create a new question on the front page, thanks.

Dec 11 '09 at 05:16 PM PatHightree
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1252
x349

asked: Dec 09 '09 at 02:20 PM

Seen: 5580 times

Last Updated: Jul 21 '11 at 11:13 PM