Download

How to make an object only show up in a USceneCaptureComponent2D?

Hi. Rather new to Unreal engine although long time C++/DX programmer.

Having issues getting an object (In this case, an artificial horizon indicator) to show up in a render texture (via USceneCaptureComponent2D) but ONLY that render texture and not in the real world.

I would prefer not to use hacks like just putting the object far, far away, or using some really strange shader to stop it rendering as this seems like it would be a very basic render feature and hacks usually bite you later down the line.

I have tried putting the UStaticMeshComponent and USceneCaptureComponent2D in an actor, and using ‘Only owner see’ on the mesh, but then it disappears from in game and the render target view. (The USceneCaptureComponent2D seems to have the same owner as world camera?)

I am already using the ''Use Showlist only" mode so the USceneCaptureComponent2D only renders the UStaticMeshComponent

Here is the source for my Actor component.


#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Components/SceneCaptureComponent2D.h"

#include "NavballActor.generated.h"


UCLASS()
class FURBALLSPACEPROGRAM_API ANavballActor : public AActor
{
    GENERATED_BODY()

public:    
    // Sets default values for this actor's properties
    ANavballActor();
    /** StaticMesh component that will be the visuals for our flying pawn */
    UPROPERTY(Category = Mesh, VisibleDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
        class UStaticMeshComponent* NavballMesh;
    UPROPERTY(Category = Mesh, VisibleDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
        class USceneCaptureComponent2D* SceneCapture;

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;



};


#include "NavballActor.h"
#include "Engine/StaticMesh.h"

// Sets default values
ANavballActor::ANavballActor()
{
    SetOwner(this);

    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
    NavballMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("NavBallMesh0"));
    RootComponent = NavballMesh;

    SceneCapture = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("NavBallCapture0"));
    SceneCapture->AttachTo(NavballMesh);
}

// Called when the game starts or when spawned
void ANavballActor::BeginPlay()
{
    Super::BeginPlay();

}

// Called every frame
void ANavballActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}