Download

How to access child components?

Hi,

I have a question about blueprints and child components.

I made a little test level to preview and display my materials. I started with a blueprint which contains a box mesh, a spotlight and a text render component. The construction script displays the assigned material name in the text component.

SlateView.JPG

SlateGraph.JPG

9a1ea73ef2b2d38fc267e566e035456eb1fbf49d.jpeg

That works. Woopie! :smiley:

Now I created a room which contains 16 of those display blueprints as child components.
I added 16 variables for mateials (instances) to the room blueprint.

RoomEditor.JPG

But how do I now access the child components (Slate01 - Slate16) in the room construction script? :confused:

RoomGraph.JPG

I also tried with “get child component” on the Slate01-getter, but all I end up with are incompatible pins… :frowning:

Any help is appreciated.

Cheers,
Klaus

Cast to the parent BP referencing the child

Hmm. This one-liner doesnt quite explains it… :confused:
Im kind of a novice with blueprints… So how does it work? :o

The variable of “Slate01” that has to be changed is called “Material”.
If I change that value, the slate-construction script will do the material/name change, right?

What do you mean with “parent” in this case? The slate display BPs are based on “actor”.
In the room, they are child components of the room, so the room is the parent.
The room BP itself is also based on “actor”.

If I make a cast to the MaterialSlate BP, the cast fails…:

RoomEditor2.JPG

Cheers,
Klaus

Ohh, I thought each Slate was based off of a parent…

Hmm, to be honest I can’t quite understand how your setup is, sorry

Ah ok. I try to explain what I did.

I created a blueprint based on “actor”. I put a box(mesh) in it, called “MaterialSlate”. I added a Text render component with the name “NameDisplay” and a public/editable variable called “Material” of the type “Material Instance”. (See first screenshot).

Then I created another blueprint, based on “actor”. I put some meshes in for walls, floor and ceiling.
I added then 16 “MaterialSlate” blueprints (dragging them in friom the content browser). I named them “Slate01” to “Slate16”.
I further added 16 public/editable variables, named “Slate01Mat” to “Slate16Mat” of the type “Material Instance”. (See last screenshot).

Alright, I did recreate your setup, and I can see why you’re having issues… Is there a reason you’re doing this way? It’s a convoluted mess (at least my recreation is)… Not to insult, but holy moly there are much easier ways to do this… Unless of course you’re doing it this way for a reason

Anyways, for your cast to go through you need to “get child actor” from slate 01. But it won’t work because of the way you set everything up

EDIT: I made a couple of changes to the way you have it setup and made this… This is what you’re going for right?

mats.png

Well, I thought it would be a “clean” way of doing it. From programming Im a bit used to the way of OOP thinking, which I use very strictly in my projects.
The MaterialSlate BP is supposed to be a black box which only offers that material instance variable to the outside.
For the room BP it should be of no concern what the MaterialSlateBP does with it (encapsulation/information hiding).

No insult detected :slight_smile: What would be a much easier way? My approach was based on some “that how i would do it in code” thoughts…

My initial thoughts as well…

In how far is my setup preventing it? Where is the “catch” so to speak?

Yeah, that looks pretty much like I wnat it. How did you set it up?

a little update:

I played a bit around and now my room construction script looks like this:

9a2172d6f209df6f23f9be75e2461cb7c1ea6540.jpeg

This is just an example for the first two panels. The rest could just be chained in the same way…
My problems with understanding casting was that I somehow thought the “Slate01” was alrweady typed as MaterialSlate-BP.

215a09a5c584835e9292de5bb7b6b0d5cccbc62e.jpeg

So the material is set by the room, however its setting it directly, not triggering the construction script. Thus, the name is not set on the text renderer.
This is not so surprising as I access the first component (which is the static mesh).

469959804f26a020daa161b7d6e5aa617d08b250.jpeg

I would need to access my variable from the MaterialSlateBP from the room. How do I cast to/access a variable?

Wait, so you actually got the materials to work using only the construction script? The issues I was having were all related to doing it all in construction… Not sure why, but you got it to work?

Anyways, the main change I made was I moved the slate code to the event graph. But now that I look, you may not want this because you’re never actually hitting play, you want to see it all in the viewport of the BP right?

The easy way I was referring to was simply dragging the material onto the slates, and typing in the text. No code require :stuck_out_tongue:

Aaand, you can access the variable the exact same way as before, except you should cast to the actual slate BP and set both variable that way… or cast directly to the component (which I didn’t know you could do)

1479f52d60fba3d28a7063d6506da832a2dc9721.png

So is the reason you’re doing it all in the construct side is to view it in the viewport without hitting play?

Ah, and linking it to the BeginPlay event.

The “Material” input of the “Cast to Slate” node is the variable? (Maybe I shouldnt have named my variable “Material” as well. A bit ambigous :rolleyes: )
What is that for a node before that Cast node?
Somehow Im failing again :slight_smile:
3602b41094c5d7c78b9b1a072e5d4bbd6115e1d1.jpeg

That would be ideal. I also thought about adding a implements a blueprint interface to the MaterialSlate BP and creating a function for the material change that implements the material/text change. But Im still struggling with BP interfaces…

I will have over 200 of these slates. That would be tedious work. Its much easier to change the material in the details panel and the name changes accordingly. And also reordering and inserting materials of the same style wouldbe easier, like having Wood1,Wood2,Wood3,Rock1,Rock2… and then adding a Wood4 in between and shift the rest…

Basically yes. Also the construction script fires everytime something changes, since Im changing materials, it seemed an appropriate place…