Function in a child BP called by the Parent?

So, to give some background. I have a Master Enemy BP. It contains the generic behaviour of all the enemies in this project. From it, five child blueprints are created, serving as each type of enemy. The generic variables in each child blueprint are slightly modified in order to create varied behaviour.

My problem lies with the unique behaviour or each enemy, specifically their attacks. Each enemy has unique attacks. A Primary, Secondary, and Melee.

I want these to be uniquely programmed into the Child BPs.

So I ask this: Is there any way to have a Function in the Child BP, that can be called from the Parent? Kinda-like how there is an “Parent begin play”. Can I have a “Parent Function” that fires when it is called from the Parent?

Specifically, is there a way to have a “Primary Attack”, “Secondary Attack” and “Melee Attack” function node in the parent, fires directly into the children BPS, regardless of which Child it is?

in theory it is possible. i know that you can create a event in the parent then call that event from the child and create a new event based on the parent one. its not something ive really looked into before though. you may need to duplicate the script not sure though.

Not sure I am understanding this correctly. Having Parent-Child relationships is so that you can script unique behavior for the children and not “re-script” common behavior. So for example, each enemy has health. This variable would be stored in the parent BP as each child will then have access to that variable and each child can “set” this variable to unique values. So default health can be 100, Child A can have health of 200, Child B 225, Child C 50, etc. Damage events if the same for all children would also be more efficient to place in the Parent BP. So if getting hit by a bullet causes damage to each enemy I would place that into a function in the parent and call it from the children whenever needed. Different weapons can have different damage, this would be a separate Parent-Child relationship for weapons, and not be an issue with taking damage in the Parent-Child BPs of enemies. Anything you want to ONLY occur in a specific enemy you script in that particular Child BP. None of the other children will have access to that script and neither will the parent class by itself, unless it is first cast to the specific child that owns that behavior. So in your case, the Master BP/Parent will hold “generic enemy behavior”, attacks would be scripted in the children as each child has 3 unique attacks.

Yes, I am well aware, and this is definitely what I am trying to achieve. What I am and requesting is if anyone knows a way to have a function called by the parent, that executes within the child.

To put it another way, what I effectively want to make is a simple communicative bridge between the Parent and child.

I want to create a custom event in the child, that the parent can call. Serving a a simple way to having a signal fire in the parent and travel over to the child.

If you get that, and that is what you’re trying to achieve I don’t really understand why you want an event in the “child” to be called by the “parent”. I am trying to wrap my head around what kind of situation it is where that would be the desired flow of execution. Can you give an example? Because what you’re describing seems perfectly handled by the normal parent child relationship and just calling the function in the child.

As stated in the initial Question. I want the Parent to be able to call one of three types of Attack in the child. Each child has unique attacks set up, but need to be called by the parent blueprint.

The reason I want an event in the child to be called by the parent, is because the Parent needs to decide when to attack and what Type of attack to use, and the child needs to perform its individual variation of that attack, (Primary, Secondary, or Melee).

I found that solution anyway. I was required to “Bind” the event with a node in order to get it to fire.

Okay, after a bit of digging, I figured it out. While I couldn’t directly call the events within the child, I can Bind them to an event dispatcher in the parent blueprint. This then allows them to be called easily.

Nice…glad you figured it out!

Thanks for providing the update. Funny enough, I had/have the exact same problem… I have an Enemy_Parent class and several child enemies and I ended up (for reasons very similar to yours) needing the parent to execute common functions dependent upon unique child behaviors. I ended up binding, just as you’ve done, and it works.

HOWEVER, I’m finding that this often causes the editor to crash when I’m editing the parent blueprint… have you noticed anything similar?

Hey. What version are you using? I can’t say I have run into this issue.

The only things I can think of is if you are using a more up to date version (I always lag a couple versions behind so that I avoid all the new bugs that haven’t been fixed in newer versions), or if this have built in the “Construction” graph.

Both of those have a fix, but otherwise I’m not sure what else I can do :S