Line trace on child actor components
I am currently trying to set up an object in blueprint, that has buttons on it that can be interacted with. Each derive from the same blueprint class, but each have different functionality.
The main blueprint actor will be called "Generator" which just uses a static box mesh. Inside of the Generator, I have created 2 Point Light components "Light1" and Light2" that are set to invisible by default.
I have another blueprint actor called "Button" which just uses a cylinder mesh.
I have an interface called "Interact" with a function called "Used" inside of it.
Both generator and button implement the Interact interface.
My character is set up so that when he hits the use key, he fires off a line trace, and checks the hit actor to see if it can do the Used function from the Interact interface.
For testing purposes. I have just dropped a generator and button object into the level seperately. Each blueprint simply prints a "Used Button/Generator" string. Upon testing, they work perfectly fine.
Now if I go to the generator blueprint and add the Button blueprint, it adds as a Child actor component. When I use the button, it prints the string "Used Button" and when I use the generator it prints the string "Used Generator". This works fine.
However let us say for example that the Generator has a function, and this function is called "Turn light1 on" I cannot call this function from within the button blueprint without doing a "Get all actors of class", casting the actor as Generator, then doing a vector distance check to get the closest Generator, before calling the function.
But lets say I wanted to use this button on a different type of object, perhaps to open a door, this button blueprint class would not be acceptable, it is not modular, it is only designed for one purpose.
So what I would like to do is make it so the "Used" event triggers inside of the "Generator" blueprint when I hit use on the Button(Child Actor Component) which would then run the "Turn light1 on" function.
Following on from that, if I added a second Button called "Button2", I would like it to run a "Turn light2 on" function within Generator.
Upon testing though. While debugging the Generator, if I hit use on the generator, it outputs "Used Generator", however if I hit use on the Button(Child Actor Component), the used event does not trigger inside of Generator, it just triggers inside of the Button blueprint, and so it does not run the "Turn light1 on" function.
Is there a way to do what I am trying to achieve? It seems like such a simple and trivial thing, yet I cannot seem to do it...at least not yet (probably brain fried).
I hope that I was clear enough :)
Thank you in advance, any help would be greatly appreciated. Meanwhile, i'll keep at it to try and find a decent solution.
asked Apr 01 '15 at 03:50 AM in Blueprint Scripting
Ok, so a bit more adventuring resulting in me getting curious about how event binding worked, so I believe I have it working how it should :)
In the Button blueprint, I have an event dispatcher called "Was Used". I then drag this function into the blueprint graph and chose "Call".
That is all I needed to do in button.
Here is a picture to show you what I have done, but first i'll try and quickly explain the Generator class. Basically I cast the child components to a Button (had to untick context sensitive in context menu), then from the object output on the cast node, I dragged the a "Bind event to Was Used" node. Which I then dragged the red binding link to the appropriate event inside of the Generator blueprint. (That probably didn't make much sense, so here is what I mean :P).
Follow this question
Once you sign in you will be able to subscribe for any updates here