Change UShapeComponent "ShapeColor" at runtime

Hello, I am trying to change the color of the ATriggerBox once it spawns. I think have the correct imports in order to use GEditor, but I am getting the error below when I compile. After the ShapeColor property is changed and I call PostEditChangeProperty(ShapeColorProperty). I then, try to re-draw the viewports using GEditor. This is where I find my issue. I get this error when I try to compile. Anyone have any advice on how to use GEditor properly? Below are snippets of: Imports, Code, Error.

Imports:

#include "UnrealEd.h"
#include "LevelEditor.h"
#include "Editor/PropertyEditor/Public/PropertyEditing.h"
#include <Runtime/Engine/Classes/Components/ShapeComponent.h>
#include <Runtime/Engine/Classes/Engine/TriggerBase.h>
#include "HitboxController.h"

Code:

UShapeComponent* comp = Cast<ATriggerBase>(HitBoxActor)->GetCollisionComponent();
FProperty* ShapeColorProperty = FindFProperty<FProperty>(comp->GetClass(), "ShapeColor");
comp->ShapeColor = FColor::Cyan;
FPropertyChangedEvent PropertyChangedEvent(ShapeColorProperty);
comp->PostEditChangeProperty(PropertyChangedEvent);
GEditor->RedrawLevelEditingViewports(true);

Hi !

Everytime i get an unresolved external symbol error when compiling like this, it’s often because i forgot to declare a module in the Build.cs

There is a module name that is “UnrealEd” , and another one "PropertyEditor " that could be the issues if you didn’t added to your build (but i’m not sure that you need both, try and tell me :grin:)

Thanks for the response. That worked to fix the external symbol error. However, the color of the trigger volume is not updating. Any advice there?

Hey I was able to solve this with a few edits. Turns out I didn’t need the GEditor in the first place. Just had to call PreEditChange() on the object before actually changing the property.

Final Code:

UShapeComponent* comp = Cast<ATriggerBase>(HitBoxActor)->GetCollisionComponent();
FProperty* ShapeColorProperty = FindFProperty<FProperty>(comp->GetClass(), "ShapeColor");
comp->PreEditChange(ShapeColorProperty);
comp->ShapeColor = FColor::Cyan;
FPropertyChangedEvent PropertyChangedEvent(ShapeColorProperty);
comp->PostEditChangeProperty(PropertyChangedEvent);
1 Like