Announcement

Collapse
No announcement yet.

How to access child components?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    Click image for larger version

Name:	SlateView.JPG
Views:	1
Size:	76.7 KB
ID:	1147895

    Click image for larger version

Name:	SlateGraph.JPG
Views:	1
Size:	85.4 KB
ID:	1147896

    Click image for larger version

Name:	SlateEditor.JPG
Views:	1
Size:	28.8 KB
ID:	1147897


    That works. Woopie!


    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.

    Click image for larger version

Name:	RoomEditor.JPG
Views:	1
Size:	28.6 KB
ID:	1147898

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

    Click image for larger version

Name:	RoomGraph.JPG
Views:	1
Size:	122.2 KB
ID:	1147899

    I also tried with "get child component" on the Slate01-getter, but all I end up with are incompatible pins..


    Any help is appreciated.

    Cheers,
    Klaus

    #2
    Cast to the parent BP referencing the child

    Comment


      #3
      Cast to the parent BP referencing the child
      Hmm. This one-liner doesnt quite explains it...
      Im kind of a novice with blueprints.. So how does it work?

      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..:

      Click image for larger version

Name:	RoomEditor2.JPG
Views:	1
Size:	44.0 KB
ID:	1072303

      Cheers,
      Klaus

      Comment


        #4
        Originally posted by KVogler View Post
        Hmm. This one-liner doesnt quite explains it...
        Im kind of a novice with blueprints.. So how does it work?

        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..:

        [ATTACH=CONFIG]34546[/ATTACH]

        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

        Comment


          #5
          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).

          Comment


            #6
            Originally posted by KVogler View Post
            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?

            Click image for larger version

Name:	mats.png
Views:	1
Size:	561.2 KB
ID:	1072307
            Last edited by vanlacke; 04-10-2015, 07:40 PM.

            Comment


              #7
              Alright, I did recreate your setup, and I can see why you're having issues... Is there a reason you're doing this way?
              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).

              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
              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...

              Anyways, for your cast to go through you need to "get child actor" from slate 01.
              My initial thoughts as well....

              But it won't work because of the way you set everything up
              In how far is my setup preventing it? Where is the "catch" so to speak?

              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?
              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:

              Click image for larger version

Name:	RoomGraph2.JPG
Views:	1
Size:	55.2 KB
ID:	1072324

              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.

              Click image for larger version

Name:	RoomEditor3.JPG
Views:	1
Size:	34.8 KB
ID:	1072325

              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).

              Click image for larger version

Name:	SlateView.JPG
Views:	1
Size:	110.7 KB
ID:	1072326

              I would need to access my variable from the MaterialSlateBP from the room. How do I cast to/access a variable?
              Last edited by KVogler; 04-11-2015, 09:49 AM.

              Comment


                #8
                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 :P

                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)

                Click image for larger version

Name:	aasasasa.png
Views:	1
Size:	149.6 KB
ID:	1072345

                So is the reason you're doing it all in the construct side is to view it in the viewport without hitting play?
                Last edited by vanlacke; 04-11-2015, 02:41 PM.

                Comment


                  #9
                  Anyways, the main change I made was I moved the slate code to the event graph
                  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 )
                  What is that for a node before that Cast node?
                  Somehow Im failing again
                  Click image for larger version

Name:	RoomGraph3.jpg
Views:	1
Size:	289.2 KB
ID:	1072354



                  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?
                  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..

                  The easy way I was referring to was simply dragging the material onto the slates, and typing in the text. No code require :P
                  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...

                  So is the reason you're doing it all in the construct side is to view it in the viewport without hitting play?
                  Basically yes. Also the construction script fires everytime something changes, since Im changing materials, it seemed an appropriate place..

                  Comment

                  Working...
                  X