BP variable to component in the same BP

I have a BP with few ChildActorComponents (that instance other BPs, Actors) in it. How can I create a variable that points to one of those ChildActorComponents or their spawned Actors (within the same blueprint)? When I try to create such a variable I can only chose to make it point to something in the asset browser or outline. But as far as I can see there is no way to make it point to something within the same BP.

If I have a BP, with a child actor component of type MySubBP. I can make a variable reference like this

image

1 Like

Thank you for a quick reply. I see that I wasn’t clear in my description :sweat_smile: What you wrote is of course valid.

So I’ve decided to prepare a simple example showing what I want to do. Let’s say that I have an actor blueprint for a chest. And in it I can set a variable defining what quality loot I want to have in it: common, uncommon, rare.

BP_chest

Then I have a blueprint actor LootManager. You provide a ‘chests’ array of BP_Chests to it and it manages how much loot is in them in total.

BP_LootManager

For example you define that all connected chests need to have 100 gold in sum. The manager will handle and randomize loot among selected chests.

And NOW I want to make an actor blueprint BP_Room which will work as a template for a room. In this room I have a few chests and LootManager that manages them. Then I can keep placing BP_Room on my map and build a level out of it, while each room has its own setting and I don’t have to copy paste it each time.

BP_LootManager

So my problem is how to connect those two chests inside BP_Room to the manager inside BP_Room so that it would know which chests to manage. All of them are Child Actor Components which, as I understand it, are components that spawn Actors. But I don’t seem to find a way to either set those actors as value in BP_LootManager’s chests variable or to get references to spawned chests and set them manually in Construction Script or Event Begin Play.

I wouldn’t do this, or anything actually, with child actor components.

I just had a quick go at this, and it’s a big mess. There’s nowhere you can sensibly put variables, you don’t know what order anything is happening in. You will end up with a casting nightmare, because the child actors have to keep asking the parent about stuff, or the parent has to do the same to talk to the children.

I’d say you’re much better off letting the room manage the loot, and spawn the chests at runtime. Nice and easy.

Up to you though… :wink:

2 Likes

I thought about this again. Maybe you can neaten the whole thing up by using interfaces.

Tell me if you’re interested, and I’ll check it out…

1 Like