Hi, I’m making an “InteractionComponent” I can use to decorate actors. This component is part of a C++ project based on Unreal’s Blueprint VR template. I rewrote the teleporting in C++, now I’m trying to flip some VR switches.
URealityInteractionComponent has two child USphereComponents to trigger overlap events each at a different radius.
When I add URealityInteractionComponent to BP_LightAndSwitch using the editor, I see both sphere’s at their default values.
BP_LightAndSwitch
- URealityInteractionComponent
- - USphereComponent (preview)
- - USphereComponent (interaction)
I can change the blueprint’s default values and see the changes to the actor on the level using PostEditChangeProperty().
However, if I select the actor on the level, then it’s RealityInteraction (inherited) component, and adjust the radius, it shows a preview of the instance value while dragging the value slider, but returns to the default once the drag is done.
How do I use the instance value in the preview? I’d like to be able to tweak these radii when designing my levels.
Thank you!
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "Components/SphereComponent.h"
#include "RealityInteractionComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class REALITYFRAMEWORK_API URealityInteractionComponent : public USceneComponent
{
GENERATED_BODY()
// ****************************************************************************************** USceneComponent
public:
URealityInteractionComponent();
protected:
virtual void BeginPlay() override;
public:
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent);
// ****************************************************************************************** Configuration
UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter=SetPreviewRadius, Category = "REALITY Interaction")
float PreviewRadius = 10.0f;
UFUNCTION(BlueprintSetter)
void SetPreviewRadius(float NewRadius);
UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter=SetInteractionRadius, Category = "REALITY Interaction")
float InteractionRadius = 6.0f;
UFUNCTION(BlueprintSetter)
void SetInteractionRadius(float NewRadius);
// ****************************************************************************************** Components
UPROPERTY(BlueprintReadOnly, Category = "REALITY Interaction")
USphereComponent* PreviewSphere;
UPROPERTY(BlueprintReadOnly, Category = "REALITY Interaction")
USphereComponent* InteractionSphere;
}
And the implementation:
// Fill out your copyright notice in the Description page of Project Settings.
#include "RealityInteractionComponent.h"
URealityInteractionComponent::URealityInteractionComponent()
{
PrimaryComponentTick.bCanEverTick = false;
PreviewSphere = CreateDefaultSubobject<USphereComponent>(TEXT("PreviewSphere"));
PreviewSphere->SetupAttachment(this);
PreviewSphere->SetSphereRadius(PreviewRadius);
InteractionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("InteractionSphere"));
InteractionSphere->SetupAttachment(this);
InteractionSphere->SetSphereRadius(InteractionRadius);
}
void URealityInteractionComponent::BeginPlay()
{
Super::BeginPlay();
PreviewSphere->SetSphereRadius(PreviewRadius);
InteractionSphere->SetSphereRadius(InteractionRadius);
}
void URealityInteractionComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
// TODO PERFORMANCE
PreviewSphere->SetSphereRadius(PreviewRadius);
InteractionSphere->SetSphereRadius(InteractionRadius);
}
void URealityInteractionComponent::SetPreviewRadius(float NewRadius)
{
PreviewRadius = NewRadius;
PreviewSphere->SetSphereRadius(PreviewRadius);
}
void URealityInteractionComponent::SetInteractionRadius(float NewRadius)
{
InteractionRadius = NewRadius;
InteractionSphere->SetSphereRadius(InteractionRadius);
}
See also: https://answers.unrealengine.com/questions/966312/view.html
and https://answers.unrealengine.com/questions/503133/view.html