x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

Product Version: UE 4.20
Tags:
more ▼

asked Sep 30 '18 at 12:05 AM in C++ Programming

avatar image

SentryTheDefiant
6 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Sep 30 '18 at 01:29 AM

avatar image

BigBadWouf
10 2 4

avatar image SentryTheDefiant Sep 30 '18 at 04:38 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question