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 Hamsword · Jun 28, 2017 at 11:46 AM · camerascripting problempost-process-effect

How to change post-processing behaviour of a camera through script?

I have two post-processing behaviours with different settings and I would like to swap them when the player dies. Is that possible, and if so, how?

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 tanoshimi · Jun 28, 2017 at 01:55 PM

Of course:

 // Include the namespace
 using UnityEngine.PostProcessing;

 // Assign the profile that you want to swap into
 public PostProcessingProfile otherProfile;

 void Update () {
   // Whatever trigger you want
   if(Input.GetKeyDown(KeyCode.F)) {
     // Assign the profile
     GetComponent<PostProcessingBehaviour>().profile = otherProfile;
    }
  }
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 sturgical · Aug 10, 2017 at 05:04 AM 1
Share

@tanoshimi, when I play in editor and actually use this script, it gets this error: "NullReferenceException: Object reference not set to an instance of an object"

I'm just dragging these things in from the project folder. Is there another way to assign them?

avatar image okaybenji sturgical · Sep 12, 2019 at 05:23 PM 0
Share

This script is assu$$anonymous$$g that it is on (a component of) the camera which has your Post Processing Behaviour on it. If you're seeing that error, it might be because your script is on some other GameObject. In that case, your code should look like this:

 using UnityEngine.PostProcessing;
  // $$anonymous$$ake a variable to access your camera (don't forget to assign it)
  public Camera camera;
  public PostProcessingProfile otherProfile;
  void Update () {
    if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F)) {
      // Assign the profile
      camera.GetComponent<PostProcessingBehaviour>().profile = otherProfile;
     }
   }



avatar image
0

Answer by AtGfx · Jun 28, 2017 at 11:51 AM

Can you just remove your behaviour and add the correct one when your player dies?

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 Hamsword · Jun 28, 2017 at 12:10 PM 0
Share

I don't think so (at least I don't know how to code it)

avatar image AtGfx Hamsword · Jun 28, 2017 at 12:20 PM 1
Share

You can check on google how to do it to fit exactly your need, but you can use the Destroy function like Destroy(GetComponent(yourScript)).

With a bit more detail (this can be a solution, but not the only one) : - define a script that will handle the switch of your components - define your 2 script like you do before with your post-processing effects - when you detect that the player dies (in your first script) you Destroy the current component and add the correct one with AddComponent

You can have a look at AddComponent and Destroy documentation.

Try to make it work, and feel free to ask for details if it doesn't work ;)

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

133 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 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

Get Camera Current Post Profile Name 0 Answers

Trying to freeze FPS character to one point for a specific amount of time 1 Answer

Many cameras with Camera.main.ScreenToWorldPoint trouble. 2 Answers

Camera.render weird issue? 0 Answers

What are the commands to change aspects of a vignette? 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