cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically create a UOCulusXRPassthroughLayerComponent

mechamount
Explorer

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

2024-06-28_08h06_46.png

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; 
}​​​​​​​

 

1 ACCEPTED SOLUTION

Accepted Solutions

mechamount
Explorer

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

View solution in original post

1 REPLY 1

mechamount
Explorer

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