Effecting post processing settings through player input with C++

I’ll preface this by saying that I am very new to C++ and fairly new to coding in general so I apologize if my code or terminology isn’t up to par.

I’ve got a game at the moment that picks up audio input from a microphone and plays it back through the speakers with a 0.4 second buffer. My question is how can I use C++ to increase a post processing effect (bloom intensity for example) while the player is making noise and then decrease the effect while they aren’t?

The function in the .cpp file that actually plays the audio back is as follows:

void AFH04Character::PlayVoiceCapture()
{
	if (!PlayVoiceCaptureFlag)
	{
		VoiceCaptureAudioComponent->FadeOut(0.3f, 0.f);
		UCameraComponent* FirstPersonCameraComponent(float BloomIntensity = 1000.f);
		return;
	}
	if (VoiceCaptureAudioComponent->IsPlaying())
		return;
	UCameraComponent* FirstPersonCameraComponent(float BloomIntensity = 1.f);
	VoiceCaptureAudioComponent->Play();
}

This all compiles fine and the audio plays back fine, but the post process effects don’t actually happen in the game itself.

I may have found the answer for what was wrong with my syntax here

I’ll be trying it out as soon as I get home tonight, will keep you all updated!

Alright I finally figured it out, you need to set a variable to carry the post processing data through a struct FPostProcessSettings myVar and then also set it to be able to override. Here’s basically what’s needed:

 //.h
//Create your camera component
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    	class UCameraComponent* CameraComponentName;

//create your variable that will carry the post processing data that you want affected
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    		struct FPostProcessSettings VariableName;
    
    
    //.cpp
//Initiate your variable
        FPostProcessSettings VariableName;

//Allow your variable to override the setting that you want to affect
        VariableName.bOverride_BloomIntensity = true;

//Set the variable to the value you want for your setting
        VariableName.BloomIntensity = 50.f;

//Get the post process settings of your camera and set them to your variable
        CameraComponentName->PostProcessSettings = VariableName;

You might need to #include “SceneManagement.h” and/or “SceneInterface.h”

With this, you can have a function that sets your variable- in my case, bloom intensity- to one value on an if statement and to another value on your else or another if like so:

void AMyCharacter::DynamicPostProcessing()
{

if (itsDarkOut)
{
FPostProcessSettings VariableName;
VariableName.bOverride_BloomIntensity = true;
VariableName.BloomIntensity = 0.f;
CameraComponentName->PostProcessSettings = VariableName;
return;
}

if(itsBrightOut)
{
FPostProcessSettings VariableName;
VariableName.bOverride_BloomIntensity = true;
VariableName.BloomIntensity = 10.f;
CameraComponentName->PostProcessSettings = VariableName;
return;
}

}

Feel free to check the API here for a list of the different values you could control this way!

1 Like