FObjectFinder a Blueprint Actor Component in C++

Hello everyone,

I’m having trouble finding the correct syntax to find an Actor Component.

This Actor Component is a Blueprint “BP_HeroAC” that is a child of the C++ Class “HeroAC” .

PlayerController.h

UHeroAC* HeroActorComponent;

PlayerController.cpp

static ConstructorHelpers::FObjectFinder<UHeroAC>HeroACTemp
(TEXT("/Game/Character/BP_HeroAC.BP_HeroAC"));
    
HeroActorComponent = HeroACTemp.Object;

I know the path is good, but I’m not sure about the overall syntax.

Thanks :slight_smile:

I did that but I didn’t use the class directly, but UClass

	static ConstructorHelpers::FObjectFinder<UClass> PlayerPawnBPClass(TEXT("Class'("/Game/Character/BP_HeroAC.BP_HeroAC'"));
	if (PlayerPawnBPClass.Object != NULL)
		DefaultPawnClass = PlayerPawnBPClass.Object;

After you can cast it to you class type.

D.

Are you calling that in the constructor of your actor?

Try it this way:

static ConstructorHelpers::FObjectFinder<UHeroAC> HeroACTemp(TEXT("HeroAC'/Game/Character/BP_HeroAC.BP_HeroAC'"));

And do it in your constructor.

Did one of the answer work for you?