Repeat Q since 2015: How to change Variables of Child Actor Component, in a BP instance?

Many have asked this for years.

  1. In UE4.27, how can we go to World/map view, click a Blueprint (Lootcrate BP), and edit the Variables (details panel) of a Child Actor Component (Pickup01 BP) that is inside the Blueprint –
  2. – without using a CastTo the name of the [Child loot] because I wont always have the same name or classes (there is Pickup02, Pickup01, Weapon01, etc).
  3. Or if I have to use CastTo, how can I do a wildcard cast (or code a wildcard so I can select from a list of Pickup BPs, without always changing the Lootcrate BP code)?
  4. I also need the [Child Actor Component] or its [replacement Pickup Actor] to be referenced in the Construct code of the Lootcrate BP, so that when I select a different [Pickup BP] that is in the Crate, then the Editor shows an update before playing (so as a dev I can quickly see which Crate will spawn what).

The community asked for years, feature requests were filed (and now the link is broken, so I cant see what was the decision).

Details:

  • I have a main Lootcrate BP actor. Inside of that is a Child Actor Component.

  • In the Right details panel, I set this Child Component as the real Pickup01 Actor.

  • Now while in the BP of the Lootcrate, I can edit the variables of [Child Actor Component, and thus the chosen PickupActor] - set its colors, tier, etc (the PickupActor has the code for all that, by reading from a DT. Im just selecting what the LootCrate spawns with so far).

  • But the problem is I want to place Lootcrate BP in the map, set it to hold Pickup01 near a tree. Then place another Lootcrate BP near a rock, and I want it to spawn a different PIckup02 that I manually set from World view.

  • But I cant because I cannot change the code/variables of the Instance copy of the Lootcrate BPs in the map. And even if I click the Child Component Actor, it doesnt show me its Variables in the details panel (in world view = map view) – as it did when I was in the BP editor.

  • So back to the BP editor. I wanted to add an Actor Variable to Lootcrate BP because I also need code in the Construct script to turn the [Child Actor Component] into whatever [Actor variable] that I set.

  • But problem 1, how do I turn the [Actor variable] into the [Child Actor Component] or replace it, so that in the World view, I can click on the Instance of the Lootcrate BP, and edit the variables of each [Actor variable]? While also on Construct, it updates to display in the map, the current [Actor variable]?

  • Problem 2, even when I add an Actor Variable (and set it as Pickup01 or 02), I still cant access its variables to set its tier, etc. (I can only access the variables of the Pickup01 BP if I set it as a Child Actor Component.)

  • So in Construct, I need to change Actor Variable (the chosen Pickup BP) into Child Actor Component or something that I can edit the variables of, in the World view.

Please help, thanks :slight_smile:

1 Like

First thing, you’re not setting the Child Component as the Pickup01 Actor. You’re setting the Child Component to Spawn an Actor that is based on the class “Pickup_Test7c” thing there.

Child Actor Component does not create actual actors in your levels when you place them. Child Actor Component spawns instances of actors when they begin play.

That is correct. You’ll need to either approach this from a different fashion, or make a blueprint for each type of loot you’d like to attach to it.

Nope, that’s already handled by setting the Child Actor Class and Child Actor Template properties in the blueprint, and leave it alone. If you need multiples, create more blueprints. (or approach this with a different tactic)

In general, if you think you need to do something in Constructor, you probably are approaching the thing from a way that will turn into a Foot Gun very quickly. Not always, sometimes there are some things you really have to do in Constructor, but they are usually pretty few and far between.

Ultimately, the reason why there’s not been a satisfactory answer that tells you how to do it, is because you’re not supposed to do it. If you want to have a bunch of Actor As with ChildActorComponent Child Class B, C, D, and H … then you should make a blueprint based on Actor A for each one, and set the Child Class and Template how you want them.

If you have many different things to cast to, you can cast to the lowest common denominator in their chain. Make a class PickupBase and all of your PickupActors should be children of that class. Then you can cast to PickupBase and you’ll be able to access any functionality inside PickupBase from there. You can also use Interfaces to do a similar thing.

1 Like

Thanks for the detailed reply. I’ll reply to everything you said later, but a few quick replies if that helps you give me a solution:

This is what I want, to set the settings (of chosen Actor) from Child Actor Template properties - not in the blueprint - but in World view. Is that possible? Either by converting Actor Variable to Child Actor Class (component), which then spawns the real Actor on Begin; but in the Construct code I can feed Actor Variable settings to Child Actor Component?
(Meaning I need any conversion method that works, so that I can feed variable settings to the final Child Actor, which spawns the real one; but I need instance edible settings for each Crate BP that I place in the level (instances/copies).

Ok so my Pickup03 is an armor set (6 individual parts, each can be set separately with 6 DT row handle variables). It has complicated code to read a DT and each EACH armor piece in its Construct script.
So for head, chest, legs, boots, etc - in that Pickup actor, I just use a dropbox variable - to select which DT row to read, and the Construct script then sets the Mesh, color, name of the matching Row handle.

But then I need to spawn that Armor Pickup BP in the LootCrate BP, or Armor Rack BP. So I need to get at the Pickup BP’s dropbox settings, to set which parts of the DT armor to spawn (because I can mix and match, or sometimes I want a Crate to spawn just boots, not all pieces - thus I need to be able to instance edit the variables).

And I need an actor inside an actor because I have some Pickups that spawn with physics shells, so they shoot out of the Lootcrate (as actors with a physics collision box that is separate from Crate BP), and when the box hits the ground, the physics box deletes, so the pickup doesnt move/push anymore. So it’s easier to have separate BP actors.

Yes Ive thought of this. But do you have examples of each - how exactly to CastTo or BPI to the Child actor/component - so that I can access their variables from the Details panel in World view?
E.g. for the Pickup03 armor - I have 6 DT row variables, which then read the DT for each armor piece. So how can I add DT row variables in LootCrate BP (this part I know how) > to CastTO or BPI affect the [Child Actor] that is spawned (dont know how)? And do I need that code in BeginPlay?

  1. (I’m not sure how to affect the spawn or Construct-change of Child Actor Component) - since Component variables have mismax.)
  2. {I’m thinking something like At BeginPlay, Set Child Actor Component > To [what type of actor and How - Get parent?] >
    … then CastTo the new [actual Actor] > set its variables by reading DT from my [DT row handle variable] in LootCrate BP (and thus Pickup03 no longer sets its armor from its DT code, but now the DT code in LootCrate BP)? But I dont know exactly the first steps, so I need to see a code example.}
    Thanks

Well I disagree because even with the other guy’s usecase, he had a Dresser BP and things inside the drawer BP, that need to be separate.
Or if I want to make a HotelRoom BP and inside that is an Physics Chair BP. I would want BPs in BP for 1) the spacing to be exact for all units, 2) I need to place 20 HotelRooms in a map (which need code for Open doors), and 3) I need to edit the Chair BP later, and its collision boxes need to be separate from the HotelRoom volumes.
(Im from UE1 and grouping meshes together into BPs, and adding code - is much easier on design/updates, instead of placing individual parts in a Map - ill never do that again because it wastes so much time when I need to change groups of things. And I dont want to use map > Groups because I will make many Maps, thus I want BPs premade that contain Rooms + items spaced correctly - I can access from the Project. So I do not understand why Epic did not already make what my question asks for. )

You could make your own Actor LootBox that spawns other Actors. It rather sounds like from some of the use cases you mention, that you don’t want Child Actor Component, if you’re destroying the crate but not the child.

and that’s not how ChildActorComponent works. You can’t change the Actor that it generates in an instance, you can only change it in the base blueprint. You can’t access it from Constructor because neither the Component nor the Actor it spawns exist at Constructor time. If you want to use ChildActorComponent, then you’ll need to create an Actor Blueprint for your possible options, and create a Blueprint of the Lootbox Actor for each Child Actor type.
The properties for the actor to spawn are not instance editable.

so, make a blueprint BP_MyPickup_WhateverTheArmorIsCalled or some such, that has all the correct settings setup by default. Create another blueprint of your BP_LootBox, such as BP_LootBox_ArmorName, and set the BP_MyPickup_WhateverTheArmorIsCalled as your child actor class.

These are two completely independent concepts that have absolutely nothing to do with each other. I don’t know how to answer, because the question doesn’t make sense.

I can’t come up with any reason why a LootBox would need to access deeply inside an actor inside it. I’m not even sure how to get a Child Actor inside the parent, because I’ve never had to do that (I do occasionally use ChildActorComponent, though)

I don’t know what the best system is for doing that, but I suspect it’s not Child Actor Components. Can you even specify where those spawn in relation to the parent? I’ve never tried.

You seem to be all onboard with making a blueprint for things, so i’m confused why you’re not wanting to make a blueprint for the things you really need to make a blueprint for to use. :smiley:

1 Like

Hi, thanks for the replies :slight_smile:

That’s what I want. But please clarify:

Crate BP = Parent, and Loot BP = Child inside Parent.

  1. Spawn Actor inside Actor: If I have Crate BP with an Actor variable (my third pic above) of the Loot BP - is there a way to instance edit the properties of the Loot BP, while in World > Details panel? (This is what I need.)

Or when you said this, did you mean it applies to both Child Actor Component spawns AND Actor (Actor variable = purple) spawns?

  1. Spawn Child Actor Component inside Actor: And it seems I cannot access Child Actor/replacement Actor properties [in an Instance] - because you explained that “You can’t access it from Constructor because neither the Component nor the Actor it spawns exist at Constructor time.” So I should not use Child Actor Comp, correct?
  • But in BP view (Graph Editor), the original copy (single copy that changes the settings for all) of my Child Actor Component IS existing and displaying inside the Crate BP at Construct - because thats how I select 6 armor pieces (while inside the Crate BP > at the Right Details panel > “Child Actor Template”).

Then the Construct script (in Child Loot BP) reads the updated DT row handle > pulls data from Table, and updates the mesh displayed for that armor piece while inside the Crate hollow - but only for the original version of Crate BP. If I change Child vars again (in Graph), all Crates update to reflect the same settings.

  • So sorry for my confusion, but you are saying [in an Instance of the Crate BP > placed in a Map], that that version of the Child does not exist yet - and that is why I cannot access/change its properties in Worldview? And thus I should not use Child Actor Comp for my goal?

My clarification: I am not destroying the Crate or Dresser, etc - they will stay visible and look empty. Only that I need the Crate BP (Parent/Holder Actor) to be separate from the Child/Spawned/Other Actor:

  • because I just remembered I will also spawn Weapons, which have their own Pickup/drop code (and collisions boxes) for long after the Player collected it from Crate BP (thus Weapon BP needs to be independent of Crate code).

This is not feasible for me because each armor pickup can have 1 to 6 independent parts that can mix/match - read from a DT. Meaning for each Crate BP, I need to edit 8 variables/variatons of the Loot pickup (armor). So I want to be able to edit Crate 1 to spawn boots… but I have 20 Boot versions in the DT – so I cant make 20 versions of Crates for each boot. Crate 2 will spawn random parts, Head and boots, or Head and top - selecting from a list of 200 DT options. Thus it is too tedious to make 200 copies of Crate BP to define the exact loot (Child variants).

Above I explained why. And I saw someone else’s example. They made a Building BP, with Prop BPs inside: Desk BP, trigger Door BP, Stapler BP… We want to use Building BP because it has procedural generation code for the look/room count. And we want to populate the Building inside with other BPs that have separate trigger volumes or logic, since Player will be able to gather Prop BPs to take out of Building BP.

I dont understand what you mean – because I did make a BP for Crate, and BP for Loot type 1 (armor), BP for Loot type 2 (weapon). I need the code separate because they arent related and each is complicated.

Update: I used method #3): in Parent’s Construct Script > Get Actor of the current Child Actor Component, then CastTo [Child Actor’s] variables > Set new – (which forces Child’s Construct script to run, read DT, and Set its internal Mesh, color, stats - which will be preloaded in Parent in Editor, then final loaded at BeginPlay).

And in Parent’s Construct code, I cast to exact Child Loot BP > get Child’s variable 1 > set it equal Parent’s placeholder variable 1. Then I need to repeat the Get/Set for ~20 more variables that update the look of Loot BP (modular armor, 6 pieces).

  • Cons: This is tedious (to make copies of Child’s vars in Parent) because I am calling a Function inside Loot BP (armor setup), which needs 6 variables per armor piece since it uses the Player’s Skeleton/animation for modular armor. So in the pic below, I did the work for 2 armor pieces.
  1. But can you help me: how can I replace the CastTo Node or use BPI? (I know how to setup BPI, but unclear on the specifics, when to set an Input vs Output in the BPI, and if the Message or Function goes in the Sender BP or Receiver BP?)

  2. Or can you show how to Wildcard (name) cast? (I can make a master Loot BP, and have Children Loot BPs as you said, so they are the same class. But still, if I switch the Loot to spawn in Crate BP (Child Actor Component or Actor variable), then what is the code to determine which Child Loot variables to get?)

  3. How can I avoid having to make ~8 copies of Child BP’s vars, in Parent BP?

Thank you :slight_smile: