Inside a custom USceneComponent
FVector TriggerBoxSize;
class UBoxComponent* TriggerBox;
//constructor
if (TriggerBox == nullptr)
{
//Create BoxComponent for Haunting Trigger
TriggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
TriggerBox->SetupAttachment(this);
}
Then in PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
i have:
Super::PostEditChangeProperty(PropertyChangedEvent);
TriggerBox->SetBoxExtent(TriggerBoxSize);
When I drag the Values for changing the TriggerBoxSize in the editor, I see the BoxExtent change with it, but when I let go BoxExtent reverts back to default values in the Blueprint. No defaults are set in C++
Why can’t I change the BoxExtent to something other than default in blueprints?
you need to expose it to blueprunt using a UPROPERTY() setting. Depending on what you want to do you may need to use one of the various keywords:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Component") UBoxComponent * TriggerBox;
or
UPROPERTY(EditDefaultOnly, BlueprintReadOnly, Category = "Component") UBoxComponent * TriggerBox;
Sorry I didn’t include my UPROPERTY() tags. I had the first one: VisibleAnywhere, BlueprintReadWrite
So what’s happening is kind of hard to explain quickly. This is what happens
place 2 actors, with this component attached to both
Select first actor, Change TriggerBoxSize. BoxExtent stays at defaults.
Select second actor, Change TriggerBoxSize. First actor’s BoxExtent changes to appropriate size, however second does not change extents, until i change the values on the first actor, but then that doesn’t work.
Basically BoxExtent is only set when the TriggerBoxSize is set on different actor.
I’m wondering what actually is setting the Size of the triggerbox…
//in constructor
FCoreUObjectDelegates::OnObjectPropertyChanged.AddUObject(this, &UMyComponent::MyPostEditChange);
InitTriggerBox();
void UMyComponent::InitTriggerBox()
{
//Create BoxComponent for Haunting Trigger
TriggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
TriggerBox->SetupAttachment(this);
}
void UMyComponent::MyPostEditChange(UObject* Object, struct FPropertyChangedEvent& PropertyChangedEvent)
{
UpdateTriggerBox();
}
void UMyComponent::UpdateTriggerBox()
{
TriggerBox->SetBoxExtent(TriggerBoxSize);
}
dZh0
(dZh0)
September 5, 2018, 8:08pm
4
Where and how is this TriggerBoxSize
value declared? How is it shared between actors!?
Can you log TriggerBoxSize
in the PostEditChangeProperty(...)
once before the Super::
call and once at the end of the method?
Are you using BP so inherit from your cpp file or are you directly using the cpp in your scene?
Everything is declared inside a custom class inheriting from USceneComponent. The constructor is being called when a change is made
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
FVector TriggerBoxSize;
Output log:
Change from 50 to 200 in editor.
LogTemp: Warning: Before Super:: TriggerBoxSize: X=50.000 Y=200.000 Z=50.000
LogTemp: Warning: Initialized TriggerBox: X=0.000 Y=0.000 Z=0.000
LogTemp: Warning: After Super:: TriggerBoxSize: X=50.000 Y=200.000 Z=50.000
LogTemp: Warning: Updated TriggerBoxSize: X=50.000 Y=200.000 Z=50.000
LogTemp: Warning: After Update Called TriggerBoxSize: X=50.000 Y=200.000 Z=50.000
try UPROPERTY(EditInstancedOnly, Category = "Component")
this should let you set it directly in the scene
BP Inherited from C++. But this is a componenent class added to an actor inherited from c++
So it looks like I’m having trouble when the constructor is called everytime it changes, or is moved in editor.
Do I need to pass the FVector variable into the Init Function and set the boxExtent there? I tried:
if (!TriggerBox)
{
InitTriggerBox();
FVector temp = TriggerBox->GetUnscaledBoxExtent();
UE_LOG(LogTemp, Warning, TEXT("Constructor Init: %s"), *temp.ToString());
}
void UMyComponent::InitTriggerBox()
{
//Create BoxComponent for Haunting Trigger
TriggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
TriggerBox->SetupAttachment(this);
//Sets Size of the trigger box
TriggerBox->InitBoxExtent(TriggerBoxSize);
//problem here, FVector is read as 0,0,0
UE_LOG(LogTemp, Warning, TEXT("Initialized TriggerBox: %s"), *TriggerBoxSize.ToString());
}
What I’m doing works when I place it in OnConstruction on an Actor. Any Ideas how it may work with components?
Did you ever solve this issue?