# Use Vector Field Actor as UVectorFieldStatic

**URL:** <https://forums.unrealengine.com/t/use-vector-field-actor-as-uvectorfieldstatic/1222438>\
**Category:** C++\
**Tags:** vector-fields, unreal-engine, question, CPP\
**Created:** [July 7, 2023, 3:40pm UTC](https://forums.unrealengine.com/t/use-vector-field-actor-as-uvectorfieldstatic/1222438 "2023-07-07T15:40:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRGwcrosby](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRGwcrosby](https://forums.unrealengine.com/u/MRGwcrosby)\
**Post date:** [July 7, 2023, 3:40pm UTC](https://forums.unrealengine.com/t/use-vector-field-actor-as-uvectorfieldstatic/1222438/1 "2023-07-07T15:40:40Z")

</div>

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?

Thanks!

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));

---

<div class="post-metadata">

**Author:** ![MRGwcrosby](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRGwcrosby](https://forums.unrealengine.com/u/MRGwcrosby)\
**Post date:** [July 7, 2023, 7:43pm UTC](https://forums.unrealengine.com/t/use-vector-field-actor-as-uvectorfieldstatic/1222438/3 "2023-07-07T19:43:29Z")

</div>

I got it to work with:

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

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));

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [August 6, 2023, 7:43pm UTC](https://forums.unrealengine.com/t/use-vector-field-actor-as-uvectorfieldstatic/1222438/4 "2023-08-06T19:43:53Z")

</div>

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