# Calling a function on a Blueprint Class from a different C++ class

**URL:** <https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [April 7, 2023, 4:55pm UTC](https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870 "2023-04-07T16:55:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.carter1182](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@a.carter1182](https://forums.unrealengine.com/u/a.carter1182)\
**Post date:** [April 7, 2023, 4:55pm UTC](https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870/1 "2023-04-07T16:55:19Z")

</div>

Is there a way to access components and call their functions in this setup…

Blueprint (made in editor of type Actor)

- has a widget component (this is actually what I want to access)

C++ Class PlayerController

in cpp file I spawn the Blueprint above into the world…

In Constructor…  
ConstructorHelpers::FClassFinder BlueprintFinder(TEXT(“PathToBlueprint”));  
BlueprintForSpawn = BlueprintFinder.Class;

In BeginPlay…  
GetWorld()-\>SpawnActor(\*BlueprintForSpawn, &Loc, &Rot, SpawnParams);

while in BeginPlay I can retrieve its name…  
UE\_LOG(LogTemp, Warning, TEXT(“%s”), \*BlueprintForSpawn-\>GetName());

logs fine

Im no c++ maestro but the options Ive searched and tried in regard to gettings this Blueprint actor’s components tend to crash the engine.

Does anyone know how to do this and have tested it or is this the wrong way to go about doing what Im trying to achieve. I just figured if I can access the name that I could access its components and maybe call functions on them etc.

Thank you

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [April 7, 2023, 6:02pm UTC](https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870/2 "2023-04-07T18:02:03Z")

</div>

This is the common way to get a component:

```auto
/// AActor* YourActor = SpawnActor....
UWidgetComponent* YourComponent = YourActor->FindComponentByClass<UWidgetComponent>();

```

---

<div class="post-metadata">

**Author:** ![a.carter1182](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@a.carter1182](https://forums.unrealengine.com/u/a.carter1182)\
**Post date:** [April 7, 2023, 6:24pm UTC](https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870/3 "2023-04-07T18:24:09Z")

</div>

TY, however this is not working…  
I tried…  
UWidgetComponent\* Component = \*BlueprintToSpawn-\>FindComponentByClass()

This gives error with no member named ‘FindComponentByClass’ in ‘UClass’

Tried casting…  
UWidgetComponent\* Component = Cast(\*BlueprintToSpawn)-\>FindComponentByClass()

This crashes

NOTE: BlueprintToSpawn is a TSubclassOf , this probably makes a difference somewhere

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [April 7, 2023, 6:34pm UTC](https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870/4 "2023-04-07T18:34:24Z")

</div>

The issue is that you are trying to call functions on a UClass instead of on a spawned actor. You get that spawned actor pointer from the return value of the SpawnActor method (my example). That is what you need to call FindComponentByClass on.

> [[BP] Whats the difference between variable of class and object?](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830)

---

<div class="post-metadata">

**Author:** ![a.carter1182](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@a.carter1182](https://forums.unrealengine.com/u/a.carter1182)\
**Post date:** [April 7, 2023, 7:18pm UTC](https://forums.unrealengine.com/t/calling-a-function-on-a-blueprint-class-from-a-different-c-class/873870/5 "2023-04-07T19:18:40Z")

</div>

Ahhh TY I misunderstood what you had written there…  
Now I have …  
AActor\* MyActor = GetWorld()-\>SpawnActor(\*BlueprintForSpawn, &Loc, &Rot, SpawnParams)

UWidgetComponent\* Component = MyActor-\>FindComponentByClass();

No crashes

Thanks Alot!
