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
0
Question by merkaba48 · May 22, 2018 at 11:06 PM · componentcustomassetpostprocessorcustom classmissing script

Trying to add a custom component inside PostProcessModel() in an AssetPostProcessor, but get a missing script.

I can add Unity components just fine (tried LineRenderer and CapsuleCollider), but any of my custom components I try adding don't work. I feel like I'm missing a step somewhere.

Here's the code:

 // Inside AssetPostProcessorScript.cs in /Assets/Editor/
 public class AssetPostProcessorScript : AssetPostprocessor
 {   
     void OnPostprocessModel(GameObject go)
     {        
         var comp = go.AddComponent<MyComponent>();        
         comp.someFloat = 0.5f;
     }
 }
 
 // Inside MyComponent.cs in /Assets/Scripts/
 
 public class MyComponent : MonoBehaviour
 {
     public float someFloat;
 }

The postprocessor has no complaint, but when I drag in my .fbx to the scene, the GameObject has a missing script where MyComponent should be.

I don't (want to) believe Unity doesn't allow custom components to be added in AssetPostProcessor, so can anyone help me?

(edit) Worth mentioning that I can add MyComponent to the GameObject with no problem manually in the editor.

Comment
Add comment · Show 1
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 merkaba48 · May 26, 2018 at 12:38 AM 0
Share

I guess noone knows? :(

1 Reply

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

Answer by Bunny83 · May 26, 2018 at 02:22 AM

You may want to try using Undo.AddComponent instead. This should mark the gameobject as dirty and should save your changes properly.


If this doesn't work, try adding EditorUtility.SetDirty:

 EditorUtility.SetDirty(comp);

after you added and changed your component. Note that an assetpostprocessor usually has some kind of condition when to execute the action(s). You rarely want / need this on literally every gameobject that you're importing.

Comment
Add comment · Show 1 · 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 merkaba48 · May 28, 2018 at 09:05 PM 0
Share

Thank you! I don't know why, but my issue resolved itself after I loaded up to try this fix (I had tried restarting before, to no avail).

Your info is useful regardless. I do wish I knew what changed / went wrong when I had the problem though.

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

83 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

Related Questions

Image component vanishes! 0 Answers

Is it possible to create a custom Game Component? 2 Answers

Adding a global custom component to GameObjects 1 Answer

Help removing a Custom Class from a List in UnityScript 1 Answer

2D Animation does not start 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