Implement Custom Actor Component

I created a custom UActorComponent call ArenaCharacterAttributes. The character of my game is called ArenaCharacter. I created the ArenaCharacterAttributes component because I didn’t want the ArenaCharacter to become blotted with code, however I wanted all of the characters variables to be easily edited from within the editor.

What I have done so far is I added the code below to my ArenaCharacter.h file:

	UPROPERTY(EditDefaultsOnly, Category = Attributes)
	UArenaCharacterAttributes* CharacterAttributes;

Then in the ArenaCharacter.cpp file I initialized the component with the below code:

	CharacterAttributes = PCIP.CreateDefaultSubobject<UArenaCharacterAttributes>(this, TEXT("CharacterAttributes"));

This did the job of showing all the ArenaCharacterAttributes variables in the ArenaCharacter blueprint, under the CharacterAttributes component.

However when I edit the defaults of the CharacterAttributes in the editor, it doesn’t apply to the CharacterAttributes C++ counterpart. How do I make it so when I edit the defaults in the editor, those changes also apply to the code?

Hi Ky Mercer,

The reason this doesn’t work in the way you’re attempting is because the blueprint itself is a child of the C++ class. According to all of the code in the C++ class, this blueprint doesn’t exist and none of those values you’re setting have been set. What type of function calls are you attempting to make in code that use these values?

That’s what I figured was happening. I am mainly calling getters and setters functions in the code.

I read about some changes made in 4.8 to Actor Components. Would upgrading the engine version solve this issue?

I’m not 100% sure that it would, but you could try it risk free by downloading the engine and making a copy of your project before converting, in case anything goes wrong in the conversion process.

Unfortunately it appears that upgrading to 4.8 didn’t solve it. I miss understood what the release notes were saying.

How then can I go about getting a reference to the blueprint and assign it to “CharacterAttributes” in my code?

I tried doing this myself without any issues at all, even the ones I mentioned so I apologize for that. The following is what I did to recreate this:

First I made two classes, an Actor and an Actor Component. I then gave a couple variables to the component and gave the Actor the component itself. After that, I set up a debug message to print out one of the variables from the component on tick which updates if I change the variable in the details panel of the blueprint instead of the code, as you were attempting to do. Here are a few pastebin links of all of the code files.

http:///8tKPdgNt
http:///JK2tRVY1
http:///KXgqWAqb
http:///HX6pPzSv

I hope this helps!