Download

Hiding certain objects from being drawn on a camera or SceneCapture2D object.

Is there a way to cull certain objects from a camera’s view?

I would love to know the answer too.

The engine doesn’t expose any way to do this right now. The underlying renderer supports it. It’s definitely a useful feature, I’ll add it to our backlog of features we’d like to add. I can’t promise when we will get to it though!


For coders out there, if you have a look at the code in FScene::UpdateSceneCaptureContents, it calls a function called CreateSceneRenderer. Inside that function you can see that it creates an FSceneView and adds it to the view family. An FSceneView has a member HiddenPrimitives which is a set of primitive IDs that the renderer should ignore when rendering the scene. If I were to implement this I’d do something like the following:

  1. Add a set of UPrimitiveComponents that I want to be hidden to USceneCaptureComponent:

UPROPERTY(EditAnywhere,BlueprintReadWrite,Category=SceneCapture)
TSet<TWeakObjectPtr<UPrimitiveComponent> > HiddenComponents

  1. I’d add some helper functions to USceneComponent exposed to Blueprint that help me add components and actors to it:

/** Adds the component to our list of hidden components. */
UFUNCTION(BlueprintCallable, Category="Rendering|SceneCapture")
ENGINE_API void HideComponent(UPrimitiveComponent* InComponent);

/** Adds all primitive components in the actor to our list of hidden components. */
UFUNCTION(BlueprintCallable, Category="Rendering|SceneCapture")
ENGINE_API void HideActorComponents(AActor* InComponent);

  1. Modify FScene::UpdateSceneCaptureContents / FScene::CreateSceneRenderer to take my list of components and add them to the set of hidden primitives on the view:

for (auto It = HiddenComponents.CreateConstIterator(); It; ++It)
{
	// If the primitive component was destroyed, the weak pointer will return NULL.
	UPrimitiveComponent* PrimitiveComponent = It->Get();
	if (PrimitiveComponent)
	{
		View->HiddenPrimitives.Add(PrimitiveComponent->ComponentId);
	}
}

If someone here gives it a go, tests it, and it all works add a pull request and you can help us get it in more quickly!

Thank you.

Is it possible to say instead of ‘hide A and B and Z’ to tell the engine 'render only A and B’?
In terms of performance and maintenance wouldn’t it be better?

What I’m trying to achieve here is a way to render my FPS weapon separately (so I can have a different FOV for the world scene and the weapons amongst other advatages)

Would this be a good solution or would you recommend another scheme?

You’re right, if you only wish to render a small number of objects it would be better to “whitelist” them. The renderer supports that for debugging but it’s not exposed very well. E.g. we can freeze visibility for a view and move the camera around to see how well the occlusion system is working. In code look at the FrozenPrimitives set on the view state.

Adding a similar construct on the FSceneView itself would be the best solution.

Thank you Nick, this sounds great!

How will shadows behave?
Say you have an object A casting a shadow on an object B. We have 2 cameras and each of them is hiding a different object (A or B). Will B still get the shadow of A?
If not is there a reasonable way to do that?

Thank for your answers they are very helpful.

If a primitive is explicitly hidden for a view it will not cast a shadow. That can be overridden per-primitive such that they will cast a shadow even when hidden:


	/** 
	 *	If true, the primitive will cast shadows even if bHidden is true.
	 *	Controls whether the primitive should cast shadows when hidden.
	 *	This flag is only used if CastShadow is true.
	 */
	UPROPERTY(EditAnywhere, AdvancedDisplay, BlueprintReadOnly, Category=Lighting)
	uint32 bCastHiddenShadow:1;


See FPrimitiveSceneProxy::IsShadowCast for the code that decides whether a primitive casts a shadow or not.

ive got a question to throw on this for you guys, finally figured out how to set this capture 2d up and setup the render image, or so i thought, my problem is that my texture on my mesh is throwing a tiled version up (multiple images) is there a good tutorial somewhere on how to set this up properly, ive got an entire level thats going to rely on mirrors of different sizes ? thanks in advance for any help

FYI we’ve exposed the ‘render blacklist’ feature both for blueprints and code and have sent a pull request on Github so everyone can enjoy it.

Thank you Nick :slight_smile:

I’ve integrated your pull request in to main and it will be in 4.3. Thanks for the submission bigzer!

Was this implemented? I can’t find anything about it on 4.5.

I’d also be interested in knowing :slight_smile:

Bump. Also interested in this feature.

Just came across this thread, but it looks like this feature was implemented in 4.3. You can use it by dragging off of a Scene Capture actor or component reference in a blueprint, selecting the “Hide Actor Components” or “Hide Components” nodes, and passing a reference to the Actor or Component you want to hide in this Scene Capture:

SceneCaptureHideComponent.png

You can also set the viewport show flags for a Scene Capture component in the advanced section of the scene capture properties:

SceneCaptureComponentShowFlags.png

How do you get to this advanced panel ? I don’t see anything like that on my scenecapture2D component. The last thing from this screenshot I see is Max View Distance Override, and then I see Film right after that, but no advanced props.

These viewport show flags are very useful.

but, where can I find these flags in Scene Capture component?

Same problem here:

  • When I add a Scene Capture 2D actor in a level, I can access this show flags window
  • When I add a ScenCapture2D component in the third person character blueprint, I can’t access this flags.

Once in game, what can you do if you want to show a component again?
I can’t find any “Show Component” or “Unhide Component” node.

Also: why is this feature only implemented for SceneCapture Actors? It would also be useful for Camera Actors, specially for the view of the player.

Does anyone have an idea about showing again a component?

Is this feature implemented for UCameraComponents?