Adding FVector to array in editor using linecast


I’m trying to fill an array (of FVector) in the editor, using PostEditChangeProperty. The array should be filled with results from a line cast. However it doesn’t let me add to the array after the linecast check. The debug does draw at the hit location (so it looks like it actually gets a valid FVector from the hit result).

Also, when I manually add a FVector to the array (in the same function) before the linecast it does work.

Could anybody please explain why this isn’t working?

thank you!


        void DoSomething();

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "PostEdit")
        bool Trigger;
    UPROPERTY(BlueprintReadWrite,EditAnywhere, Category = "PostEdit")
        TArray<FVector> MyArray;


void UMyActorComponent::PostEditChangeProperty(struct FPropertyChangedEvent& e)

    FName PropertyName = (e.Property != NULL) ? e.Property->GetFName() : NAME_None;
    if (PropertyName == GET_MEMBER_NAME_CHECKED(UMyActorComponent, Trigger))

void UMyActorComponent::DoSomething()
    FCollisionQueryParams params;
    FVector Start = FVector(0, 0, 500);
    FVector End = FVector(0, 0, -500);
    FHitResult Hit;

    if (GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECollisionChannel::ECC_Visibility, params))
        DrawDebugPoint(GetWorld(), Hit.ImpactPoint, 10.0f, FColor::Red, true, 10.0f, 0);

Is the Blueprint placed in the level?
If you want to modify Blueprints and keep changes you usually have to call BP->Modify() on it before you make changes to the default object in Editor.

Hi Bruno, thanks for your reply!

It’s inside the blueprint editor/viewer, so not placed in a level. Would that also need to call the modify function?

If it’s in the Blueprint viewer than you are modifying the asset.
I’m not sure I would do that inside PostEditChange, but yeah you have to notify the Editor you’re about to modify the Blueprint asset.

Thats what I thought, but it doesnt seem to update in the linetrace. And when I modify it outside the linetrace it gets updated correctly, what I don’t really understand .

It appears I get a NULL from GetWorld(). Which is quite strange, since its also used for drawing debug, and those are working…

Is there any way to get the (editor) World from inside a component?! (using GetOwner() also returns NULL)

thank you

There’s no world inside a Blueprint, also the owner is null since it wasn’t instantiated inside a map.

Is it somehow possible then to do a linetrace from inside the (blueprint) editor? Using construction in blueprint allows you to, yet I cant get it to work in c++ using OnConstruction either…

I don’t know, there might be way, but feels like fighting against engine architecture to do this; feels hacky.

I would maybe spawn the thing on map then use it to change default values of CDO instead.

I managed to get it working in the editor viewport by using GEditor->GetEditorWorldContext().World() and doing a linecast from there

thanks for your help and input on this Bruno!

No problem, I didn’t even know GEditor was exposing World() to use… Now I know lol
Thanks for sharing. I always note these things, this is why I keep on lurking the forums =]