Use Vector Field Actor as UVectorFieldStatic

Hi, I am trying to access the vector field actor I have placed into my world. I want to run the FilteredSample function on it. The code below causes a crash with error message “Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x000000000000005c”, so I assume the cast to the UVectorFieldStatic is failing.

How can I make this work?


AActor* VecField = UGameplayStatics::GetActorOfClass(GetWorld(), AVectorFieldVolume::StaticClass());

UVectorFieldStatic* StaticVectorField = Cast(VecField);

FVector Sample = StaticVectorField->FilteredSample(FVector(0.0, 0.0, 0.0), FVector(0.0, 0.0, 0.0));

I got it to work with:

AActor* VecFieldActor = UGameplayStatics::GetActorOfClass(GetWorld(),

AVectorFieldVolume* VecFieldVolume = Cast<AVectorFieldVolume<>>(VecFieldActor);

UVectorField* VecField = VecFieldVolume->GetVectorFieldComponent()->VectorField;

UVectorFieldStatic* VecFieldStatic = Cast<UVectorFieldStatic<>>(VecField);

FVector Sample = VecFieldStatic->FilteredSample( FVector(0.0, 0.0, 0.0), FVector(0.0, 0.0, 0.0));

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.