Forum rules - please read before posting.

How to toggle/trigger/switch on image effects on main camera through AC?

I am trying to toggle visual/image effects on the main camera on or off, but with no luck. I’ve scoured the forums and seen posts regarding the similar.

I have my effects all on the main camera, as recommended. Such as Bloom and Blur.

I’ve read I need to create and attach a script such as the following to my Main Camera to then be able to use the AC method – Object > MainCamera > ???  > Send Message > Turn On or Turn Off.


 void TurnOnEffect ()

{

  this.GetComponent <Bloom>().enabled = true;

}

 

void TurnOffEffect ()

{

  this.GetComponent <Bloom>().enabled = false;

}

What other code do I need around the above as Unity doesn’t like this as it is? I know this isn’t a general unity programming forum, but im hopefully somebody can help my with how to get this working with AC. Hope do I tell then the AC script to Turn On or Off each specific image effect?

I found the AC Light Switch trigger fantastically easy to use, I hoped that triggering camera image effects was going to be just as easy.

Thanks

Comments

  • Ah, I think I have a solution from rewriting the light switch code - I shall have to post later when tested.
  • The code posted above should work just fine, though the "Turn On" / "Turn Off" functions in the Object: Send mesage Action are labelled only out of convenience, because many of AC's scripts contain functions with these names.

    To call the functions in your script, you would have to set your Message to send to Custom, and then enter in the name of the function (e.g. TurnOnEffect) into the Method name box.
  • I have zero coding knowledge but I managed to cobble together this script based on the discussion here and other places. Anyone else that doesn't know where to put the above suggestions exactly and is looking for a way to toggle/ turn on/ off post processing effects using Adventure Creator can just copy paste this whole code and attach it to their main camera as Chris said.

    ("CameraEffect" is the name of the script. Be sure to add "using UnityEngine.PostProcessing;" I wasn't able to use <PostProcessingBehaviour> without it)

    I'm sure there's a lot wrong with this code, or it has some redundant lines, but it works! :P


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine.PostProcessing;
    using UnityEngine;

    namespace AC
    {

       
        [RequireComponent(typeof(PostProcessingBehaviour))]

        public class CameraEffect : MonoBehaviour
        {
            
            public bool enableOnStart = false;

            // Use this for initialization
            void TurnOnEffect()
            {
                this.GetComponent <PostProcessingBehaviour>().enabled = true;
            }


            void TurnOffEffect()
            {
                this.GetComponent <PostProcessingBehaviour>().enabled = false;
            }
        }
    }


  • edited May 2018
    @armaan There's no easy way to create options for graphic settings... The way to change the settings for effects depends entirely on what effects scripts you are actually using (which could be from the old standard assets, the deprecated Cinematic effects, post processing stack or even third party effects).

    Your code there will work to turn on or off the post processing stack v1. Though it'll disable the whole thing. I've worked with making options UI for the Post processing stack v1 before, but the ways to change the settings of particular effects through code is a pain in the ass though.

    I used to have a post processing profile switcher, and I changed some effects based on some static settings I had.
  • edited May 2018
    using UnityEngine;
    using UnityEngine.PostProcessing;

    //...........................then inside the class

    public PostProcessingProfile NewProfile;

    void Start()
            {
                if (NewProfile == null) return;

                var ppsBehaviour = Camera.main.GetComponent<PostProcessingBehaviour>();
                if (ppsBehaviour == null) return;
                
                var newProfile = Instantiate(NewProfile);

                newProfile.antialiasing.enabled = Globals.AA_State;

                if (newProfile.antialiasing.enabled)
                {
                    AntialiasingModel.Settings tempSettings = newProfile.antialiasing.settings;
                    if (Globals.AA_Fxaa)
                    {
                        tempSettings.method = AntialiasingModel.Method.Fxaa;
                    }
                    else
                    {
                        tempSettings.method = AntialiasingModel.Method.Taa;
                        
                    }
                    newProfile.antialiasing.settings = tempSettings;
                }

                newProfile.bloom.enabled = Globals.BloomState;
                newProfile.ambientOcclusion.enabled = Globals.AoState;
                newProfile.screenSpaceReflection.enabled = Globals.SSR_State;
                newProfile.depthOfField.enabled = Globals.DoF_State;
                newProfile.motionBlur.enabled = Globals.MotionBlurState;

                ppsBehaviour.profile = newProfile;
            }
  • edited May 2018
    That's the code to make an object in which you can set a replacement Post processing profile (for post processing stack v1).  I did change some settings immediately based on static/global variables.

    To avoid messing with the Profile asset it's recommended to instantiate a runtime copy (like I show above).

    Enabling or disabling individual effects is not as hard (they have an "enabled" property).

    But, most of the fx in V1 use a dedicated class to contain the settings for that effect. If you want to change the settings for the effect (rather than just turn it on or off) then you have to replace the whole settings "container" for that effect. That's why I created the settings container and changed the settings in this object, and only then assigned the settings container to the effect.

    You could replace the parts where I use my own globals and use AC's global variables instead (here's the tutorial showing how to use them in code). but it would basically look something like:

    newProfile.bloom.enabled = AC.GlobalVariables.GetBooleanValue (VarIdGoesHere);

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.