• 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 DoctorWhy · Jul 05, 2013 at 06:14 PM · post effects

AddComponent Doesn't work with Post Effects??

I am trying to add a post effect like Bloom to the camera using AddComponent. I immediately get a message saying a shader is missing. For a post effect like DepthOfField34, I get an error because of a missing shader. But when you click and drag one of these scripts onto the camera, they work great, but I can't find anywhere that these shaders are set, including the associated Editor scripts. Where are these default shaders set and why doesn't AddComponent do so properly??

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

2 Replies

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

Answer by Bunny83 · Jul 05, 2013 at 08:15 PM

That's probably because they set up some default references on the script. Default references are only used inside the editor when you add a component via inspector. You should either:

  • Create a prefab of an object that has the script attached and all necessary links setup and simply instantiate the prefab when you need it.

  • Search for the right shader manually in the script and assign it manually.

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 DoctorWhy · Jul 05, 2013 at 08:22 PM 0
Share

The first one won't work because the scripts have to be on a camera.

The second would work, but I was hoping to avoid that. $$anonymous$$ight have to.

The third option would be to have the post effects disabled on the camera until I need them. Not sure which route I will go.

avatar image Bunny83 · Jul 06, 2013 at 09:54 AM 0
Share

In your case i would go your third solution ;) It's the easiest one and actually avoids loading stuff in-game. Having it already in the scene has also the advantage that you can reference the script from other scripts to enable / disable the effect.

avatar image
0

Answer by supercouge · Jul 05, 2013 at 10:58 PM

If you click on the DepthOfField34 script, you should see in the inspector its default public arguments. They are however ignored if you add DepthOfField34 from a script.

A solution may be to add the default public arguments of DepthOfField34 to your own script, like this:

     public Shader dofBlurShader;
     public Shader doFShader;
     public Shader bokehShader;
     public Texture2D bokehTexture;
     
     // Use this for initialization
     void Start () {
         DepthOfField34 d = gameObject.AddComponent<DepthOfField34>();
         d.dofBlurShader = dofBlurShader;
         d.dofShader = dofShader;
         d.bokehShader = bokehShader;
         d.bokehTexture = bokehTexture;
     }

Note that I don't know why the public arguments in the DepthOfField34 are not visible, since I didn't see the HideInInspector flag...

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 DoctorWhy · Jul 05, 2013 at 11:08 PM 0
Share

This won't work exactly as I am making asset bundles and I don't think the Shaders or Textures will come over without adding it to the asset bundle specifically, but that breaks the connection. At any rate, a string name may work, but I think I found the solution for now (In Bunny83's answer).

And ya, it took me a second to find why they were invisible, but it is because they have Editor scripts that control how they appear.

EDIT: And also, the error and other log info is thrown right after AddComponent if I remember right, so I would have to modify DepthOfField34 and whatever post effects throw errors ins$$anonymous$$d of a warning or log. I want to avoid modifying those for future compatibility if possible.

avatar image supercouge · Jul 05, 2013 at 11:13 PM 0
Share

Yep, sorry. $$anonymous$$y answer had to be validated, and it took a few hours... Thanks for the precision about the editor scripts.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Glow-like effects and WebCamTextures 0 Answers

Trying to use GBuffer RT0 and only get a grey screen. 1 Answer

Apply image effect directly to object (Unity 2D) 1 Answer

Post Process v2 Layer without effects causes weird blur (bad VR experience) 0 Answers

Fade Out over length of object on Material? 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