Can I instantiate volumes through code?

Is there any way to create a volume (specifically a post-effects volume) through code, preferably Blueprints?

I have a class of moving actor that affects player’s vision via post-effects closer that they get to it. As such I need a post-effects volume to remain attached to these actors as they move. problem is that I can see no way to add a volume as a component. I can parent a volume to an actor in editor just fine, but I need to be able to do this at runtime. If I try to create a composited Blueprint out of hand-created actor/volume hybrid, it just detaches volume.

If there’s another way to achieve this, I’d also be interested in hearing. My current backup plan is to interpolate effects directly onto player’s camera based on distance to any of these actors every tick, but that sounds both painstaking and inefficient.

Hey SF,

There are certainly many ways to achieve effect you’re looking for. An easy way would be to create a Post Process Volume and set it to Unbound so it affects camera no matter where it is. Then in your Level Blueprint (or character blueprint, or moving object’s blueprint, etc), turn it on or off depending on whether player is within a certain range of moving objects.

But there’s more! I just checked our internal build, and ability to add a Post Process Volume as a component inside a Blueprint is there. It’s on it’s way! I can’t give you a firm date for that, but you should be able to do that soon.

Hi ,

So in future it will be possible to spawn a post process volume on a dynamic actor’s location via Blueprint? Am I correct in assuming that currently there is no solution for blending a post process volume relating to distance a pawn is from a dynamic actor? Hopefully, that makes sense.


— .

Thanks for suggestion with unbound effect! That should work in meanwhile.

And that’s great news about coming feature, thank you very much for checking! Firm date aside, I don’t suppose you have a guess as to whether it’d be coming more on order of days, weeks, or months? Just so I know whether I should wait for it on my current project.

hi everyone!

i just discovered that this code works:

	UObject* PostProcessVolumeObj = FindObject<UObject>(nullptr, TEXT("/Script/Engine.PostProcessVolume"));
	UActorFactory* PostProcessVolumeFactory = GEditor->FindActorFactoryByClassForActorClass(UActorFactoryBoxVolume::StaticClass(), APostProcessVolume::StaticClass());
	APostProcessVolume* PostProcessVolume = Cast<APostProcessVolume>(PostProcessVolumeFactory->CreateActor(PostProcessVolumeObj, ComplementsWorld->PersistentLevel, FTransform()));

first you get uobject that represent PP asset;
then you get factory to construct it;
finally you use that factory to create your final actor!

you can use same code to spawn all others volume related actors, for example:

	UObject* NavMeshBoundsVolumeObj = FindObject<UObject>(nullptr, TEXT("/Script/Engine.NavMeshBoundsVolume"));
	UActorFactory* NavMeshBoundsVolumeFactory = GEditor->FindActorFactoryByClassForActorClass(UActorFactoryBoxVolume::StaticClass(), ANavMeshBoundsVolume::StaticClass());
	ANavMeshBoundsVolume* NavMeshBoundsVolume = Cast<ANavMeshBoundsVolume>(NavMeshBoundsVolumeFactory->CreateActor(NavMeshBoundsVolumeObj, ComplementsWorld->PersistentLevel, FTransform()));


	UObject* LightmassImportanceVolumeObj = FindObject<UObject>(nullptr, TEXT("/Script/Engine.LightmassImportanceVolume"));
	UActorFactory* LightmassImportanceVolumeFactory = GEditor->FindActorFactoryByClassForActorClass(UActorFactoryBoxVolume::StaticClass(), ALightmassImportanceVolume::StaticClass());
	ALightmassImportanceVolume* LightmassImportanceVolume = Cast<ALightmassImportanceVolume>(LightmassImportanceVolumeFactory->CreateActor(LightmassImportanceVolumeObj, ComplementsWorld->PersistentLevel, FTransform()));

Bye :wink: