Is it possible to add ActorComponents to Actors via C++

Hello everyone!

I’m starting to recreate my BP scripting into C++, and I’m running into an issue with trying to get my C++ Actor to pull data from my C++ actor component.

My goal is to create a Fire and Reload function in the Weapon (C++ Actor) using data from the ActorComponent. The ActorComponent has the variables for Damage, Ammo, ReloadSpeed, etc. However, I cannot edit the variables from the the BP Weapon, trying to print out the default values returns null. Trying to fire from the C++ function crashes the game using a variable from the actor component. I’m able to access my variables if I add the component from the Editor but not from C++.

I want to be able to edit the ActorComponent variables from BP and call C++ functions from within Blueprint.

Here’s a link to the question on the UE subreddit with images provided

Hi,

You can create c++ Class Inherited of ActorComponent and add it to the actor via AddOwnedComponent, and get the component with property with FindComponentByClass

Hi there Im a Bamby,

Unfortunately, when I tried adding that to my PlayerController’s constructor, it crashes Unreal and I cannot find where the problem lies when debugging.