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