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
3
Question by ZanzibarDreams · Mar 31, 2010 at 03:23 PM · prefabmodelfbxmaya

Importing a model without it becoming a prefab

This may be a stupid question (I don't even know if anyone else has it), but is there a way to import models into the game without them directly turning into prefabs?

Very often I need to add scripts to a model, but I cant, because it's a prefab, and for some reason I can't add scripts to a "model prefab" without breaking the link (and I can't use apply).

This wouldn't seem like a big problem ( i can make a new prefab and drag the broken into that one), but it gets really messy.

As always, any help is appreciated!

Comment
Add comment · Show 2
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 Lipis · Mar 31, 2010 at 03:34 PM 1
Share

The question is O$$anonymous$$.. Just few notes: there is no such thing as a stupid question.. as long as it has to do with Unity.. and there is no need for asking for help.. we are all here to help and get help..!! more in http://answers.unity3d.com/faq Regards

avatar image Cyclops · Mar 31, 2010 at 04:07 PM 1
Share

@Lipis - at least he asked for help in the text - not one giant Title saying HELP!

3 Replies

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

Answer by Eric5h5 · Mar 31, 2010 at 04:05 PM

The prefabs you get when you drag in a model are not "real" prefabs. You can see that they have a different icon. The correct procedure is to make an actual prefab the usual way (Create -> Prefab) and drag the model onto that.

Comment
Add comment · Show 3 · 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 ZanzibarDreams · Apr 01, 2010 at 08:57 AM 0
Share

That's a shame :D

avatar image Eric5h5 · Apr 01, 2010 at 09:36 AM 0
Share

Hmm...I'm not sure why you think so, since the answer to your question about "is there a way to import models without them turning into prefabs" is basically "they never were actually being turned into prefabs", which seems to be what you wanted in the first place. You can drag the bare mesh into the editor if you don't want the "fake prefab" effect, but then you lose out on things like automatic texture assignment and orientation correction.

avatar image ZanzibarDreams · Apr 06, 2010 at 08:09 AM 0
Share

Now you're getting it :D

avatar image
3
Best Answer

Answer by duck · Apr 01, 2010 at 09:08 AM

There's one other option here, which is to use the AssetPostprocessor scripting.

With this, you can programmatically add components to your models during the import process (including built-in components such as Colliders, as well as your own scripts).

In this way, you can actually end up with a model with a script attached to it, which you can use right off the bat. :-)

Here's an example C# script which adds an Enemy behaviour to any object imported which contains the word "enemy" in its name:

using UnityEngine; using UnityEditor; using System.Collections;

public class ModelPostProcessor : AssetPostprocessor {

 void OnPostprocessModel (GameObject g) {
     Apply(g.transform);
 }

 void Apply (Transform transform)
 {
     if (transform.name.ToLower().Contains("enemy"))
     {
         transform.gameObject.AddComponent<Enemy>();
     }

     // Recurse
     foreach (Transform child in transform)
     {
         Apply(child);
     }
 }

}

Comment
Add comment · 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
2

Answer by duck · Mar 31, 2010 at 03:37 PM

I think your problem here is that you're thinking that making a new prefab from the "broken" one is "messy", wheras it's actually a very powerful tool which doesn't need to be messy at all - it's one of the fundamental ways that developing in unity works, and in fact what you're doing is creating a new game-ready functional prefab based on that imported model.

If you're finding it messy, you probably just need to work out a way of organising your original imported 3d assets in your Asset folder so that they are separated from your functional prefabs that you use in your game. You can do this by creating folders in your project pane.

For example, you might have "enemy.fbx" which contains your enemy model. You'd then want to create a functional prefab based on this model. So first, you'd drag the enemy model into your hierarchy (which adds it to the current scene). You'd then add any relevant scripts - such as a script which controls its behaviour, and maybe other separate scripts which might perform global actions like allowing it to show up on a radar, or allowing it to be a valid targetable item, etc.

You'd probably also want to add a collider and perhaps a rigidbody component if you're using the physics engine to move it around. You might also want to add things like a particle system for its engines, or wheelcolliders if it's a wheeled character. It might need an audio source for any sounds that it should emit, etc.

In this way, you should be able to see that you start off with the basic model, and build up a fully functional Game Object by adding components to it.

Now - you create a new prefab, and drag your completed Game Object into this new prefab. This is now the "Enemy" prefab that you should instantiate in your game - either by manually placing them around your levels, or by dynamically instantiating them at runtime via some kind of enemy manager script.

I hope this helps!

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 ZanzibarDreams · Apr 01, 2010 at 08:56 AM 0
Share

I wouldn't have to organize half as much if I could make a prefab right of the bat with assets that I only have one specific use for. cheers for the one page answer though

avatar image duck ♦♦ · Apr 01, 2010 at 09:10 AM 0
Share

I've added another answer. This answer still holds (this is the way you're supposed to use prefabs in unity), however there's a editor-scripting method you can use to add scripts directly to models as they are being imported.

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

3D Object in scene displaces or disappears after it is re-imported. 1 Answer

NullReference Exception Mecanim 0 Answers

A Prefab with animation.Play doesnt work 0 Answers

Modifying a model breaks connections 0 Answers

How can I make a Prefab from only face model FBX 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