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.
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.
But how do I now access the child components (Slate01 - Slate16) in the room construction script?
Hmm. This one-liner doesnt quite explains itâŚ
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âŚ:
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?
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 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:
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.
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).
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
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)
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
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âŚ