Skip to main content
New Participant
June 27, 2024
Solved

How to dynamically create a UOCulusXRPassthroughLayerComponent

I am implementing Passthrough with UE5.3.2 and MetaXR Plugin 1.95.0.

Passthrough works fine if I add the OculusXRPassthroughLayerComponent to Pawn in UnrealEditor and change the following parts.

  • Supports Depth:Check
  • Stereo Layer Shape: User Defined Passthrough Layer
  • Priority: -1

I created the following C++ code to dynamically create a UOculusXRPassthroughLayerComponent.
However, when I create the Component with this, Passthrough does not work properly.
What do I need to make Passthrough work?

UCLASS()
class PASSTHROUGHTEST_API UMyPassthroughComponent : public UOculusXRPassthroughLayerComponent
{
	GENERATED_BODY()

public:
	UMyPassthroughComponent(const FObjectInitializer& OI) : Super(OI)
	{
		UOculusXRStereoLayerShapeUserDefined* Subobject = OI.CreateDefaultSubobject<UOculusXRStereoLayerShapeUserDefined>(this, FName("OculusXRStereoLayerShapeUserDefined"));
		Shape = Subobject;
		MarkPassthroughStyleForUpdate();
	}
};

 

UOculusXRPassthroughLayerComponent* UMetaPluginUtils::AddPassthroughComponent(APawn * Pawn 、 boolbManualAttachment) 
{ 
	UMyPassthroughComponent* Comp = Cast<UMyPassthroughComponent>( 
		Pawn->AddComponentByClass(UPassthroughComponent::StaticClass()、 
		bManualAttachment, FTransform :: Identity, true )) ; 
	Comp->bSupportsDepth = 1; 
	Comp->SetPriority(-1); 
	return Comp; 
}​​​​​​​

 

    This topic has been closed for replies.
    New Participant
    July 1, 2024

    I noticed that TickComponent (also BeginPlay) of UMyPassthroughComponent is not working.

    I followed the following URL and executed AActor::AddComponentByClass() followed by AActor::FinishAddComponent(),
    By doing so, I was able to get TickComponent and Passthrough to work.
    https://forums.unrealengine.com/t/add-component-to-actor-in-c-the-final-word/646838/10

    1 reply

    mechamountAuthorAnswer
    New Participant
    July 1, 2024

    I noticed that TickComponent (also BeginPlay) of UMyPassthroughComponent is not working.

    I followed the following URL and executed AActor::AddComponentByClass() followed by AActor::FinishAddComponent(),
    By doing so, I was able to get TickComponent and Passthrough to work.
    https://forums.unrealengine.com/t/add-component-to-actor-in-c-the-final-word/646838/10