Set actor variable at the beginning

Hello,

I want to set a variable (Actor) to my sword which I have attached to the characters hand.
This has to happen directly at the start.
I will explain it in more detail below.

This is my CharacterBP with the functions to pick up and drop my sword.
IsHolding is set to true by default because I start with a weapon in hand.

The sword I start with is defined as a child actor, the specific sword is defined in the child actor class.
The socket is set to the socket name that the sword will be connected to.

The problem is that the “Held item” variable (Actor) is only set in the pick-up-logic.

Since I start with a weapon in my hand, I have to drop it first.
But this doesn’t work, because the variable “Held item” is not set at this moment and I get an error. “Accessed none trying to read property Held item”.

How can I set this variable right at the start to my sword that I attached at the beginning?
Or is there another solution on how to do this?

Thanks in advance

Just to understand it right:

You have Sword 1 and Sword 2 and both are childs of the same parent?

Yes, this is my weapon structure:
Both swords are inheritance of the SwordBP
image
image

Try to set the parent and drop/pickup the child

So if I’m reading this correctly your current Sword you hold at begin play is your Child Actor Component. If this is true, get your child actor, drag off of child actor and type “get child actor”.

You should get something like this:
image_2022-05-23_144108129

This will return a reference to the actor set as your child actor inside your child actor component.

Keep in mind that the Child Actor in your components tab is a component and not the actual actor!

(edited for readability)

2 Likes