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 emc233 · Dec 25, 2013 at 10:18 PM · prefabpost processingconsole

How to determine if a game object is a generated prefab using code

I am trying to add a script to all game objects in a scene. I have gameobjects created in unity and gameobjects imported from 3d model software. The ones imported from a 3d model software makes the console get mad and say "You cant add script to this gameobject because its a generated prefab and can only be modified through an AssetPostProcessor" How can I make code to check if the gameobject is a generated prefab at runtime?

Comment
Add comment · Show 3
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 iwaldrop · Dec 25, 2013 at 10:44 PM 0
Share

You don't need to use any code to check, just look at the icon and be aware of what you're doing. Unity displays imported models as blue prefab icons with a little white sheet of paper in the bottom right corner. It sounds like you're trying to drag scripts onto objects that are selected in the project window.

In order to take a 3d model and add components to it you need to drag it out into the scene, add you components, and then drag the object from the hierarchy back into the project view (into something like a prefab folder for organizational purposes).

Addendum: Last section on this page, entitled "Imported Prefabs".

avatar image emc233 · Dec 25, 2013 at 11:18 PM 0
Share

Thank you for attempting to help! However, that was not what I was asking for at all. Very good try, I appreciate it and keep up the good work.

avatar image iwaldrop · Dec 26, 2013 at 12:46 AM 0
Share

Sorry it wasn't what you were looking for, but there's no runtime code that can detect a difference. There may be something in the UnityEditor namespace, but I'm uncertain.

In my $$anonymous$$d it boils down to what you're trying to accomplish. You shouldn't ever be using the raw imported prefabs in a production environment, so it should never be an issue.

1 Reply

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

Answer by Statement · Dec 26, 2013 at 12:52 AM

I'd try PrefabUtility.GetPrefabType.

It will return you a PrefabType and I think the following is what you are after:

  • ModelPrefab

  • ModelPrefabInstance

  • DisconnectedModelPrefabInstance

Hope it helps, haven't used that API before. It would be nice if you report back with findings to help document the usage of this API.

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 emc233 · Dec 26, 2013 at 02:56 AM 1
Share

That worked great! It worked exactly how it said in api. However, the api is kinda outdated because http://docs.unity3d.com/Documentation/ScriptReference/PrefabType.html

refers to EditorUtility.GetPrefabType when ins$$anonymous$$d you must use PrefabUtility.GetPrefabType(gameObject).

Statement! I know this is not the forum for personal info, but what motivates you to help so many people out what have you done with Unity?

avatar image Statement · Dec 26, 2013 at 02:57 AM 0
Share

@emc233: Find me on IRC and we can have a private chat if you want to learn more about me. I'm Statement on #unity3d in FreeNode

Im european and it's getting a little late, so if you miss me today I may be on a different time. It's 4 am where I am staying at present.

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

21 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

Related Questions

Getting Prefab Icon from AssetDatabase 0 Answers

Predefined Dynamic Navmesh? (With image) 0 Answers

Checking Position 1 Answer

Unity: How can you make a prefab immutable for instance overrides 0 Answers

Clone of rigid body prefab destruction if at certain position 3 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