about parent and child blueprints

Hello to all, as ive started doing my little project…
I have noticed that i have been creating every objects i need with different kinds of blueprints…

for example… Floor, wall, table, chair etc…

i need to know what parent and child blueprints does, i have watched some tutorials,

as i have now know, everything a parent has , the child also gets…

but, do the child can have their own blueprint events?
how do i call a child’s events…
or even identify a child blueprint

can someone tell me what or how do they use a parent child actor for?
i have really vague idea of it, but im confused…

1 Like

A child has everything the parent has and can have all of its own stuff too.

There’s a parent class called animal. It has two variables, age and hunger. It has two events, eat and die.

You make a child class from animal, it has those same events and variables. But this child is a turtle, so you add an air variable and a swim event.

The base animal class doesn’t have the turtle-specific variables or events, nor does a separate child, tiger.

If you make another child from turtle (say, “Sea turtle”) it will have all of the variables and events of the base animal class and of the turtle class.

You can identify a child class by casting. Say you have a blueprint that you know is an animal, but you’re not sure if it’s a tiger or a turtle. Call “Cast to turtle” on the actor and the engine will attempt to figure out if this animal is a turtle or not. If it is, then you can call any turtle-specific events on the actor.

i see, but how about getting variables from the child… how do i call it…
do i call the parent’s variable? what if the child has another set of variables for itself… how do i call it?

and also, what is the difference or downside with just making another blueprint class like rabbit, or another blueprint tiger, sea turtle etc…

it is just for the purpose of casting?

i have watched in tutorials that parent and child are what it is supposed to be, but i have forgotten and right now it seems, i have been making blueprints out of every specific actor i want… it seems to be working well…

but i want to know, if i parent child some blueprints, what advantages do i get? :slight_smile:

You can change a function/event(override) so that the custom function/event does something different. It can be really useful for when you do a foreach on an Array of Parents that can is filled with both parent/children.

Animal Function: Move
Move normally simply moves the Animal from point A to point B.

Child Rabbit function: Move (overridden)
Changes the behavior completely and makes the Rabbit hop from point A to point B instead.

Child Turtle function: Move (overridden)
Changes the behavior completely and causes the Turtle to have a swimmy type movement from point A to point B.

Child Human function: Move
Not changed, so still simply moves the ‘Animal’ from point A to point B.

Another way to think about it is that whenever you make a new Blueprint class as it is, you are usually making a child of Actor, Pawn, or Character. So you are already using some inheritance without even realizing it.

i see, i get it a bit now…
thank you for the explanations… :slight_smile:

One big advantage to using inheritance is that when you have a function or variable that you want all animals to have, you can just add it to the parent blueprint and all children will then inherit it.

If you have a bunch of independent animal blueprints and want to add an aggression variable, you’re going to have to add it to each blueprint individually. If all animals derive from the single parent animal class then you can just add “aggression” to the parent and all of the other animals now have the aggression variable as well.

Same goes for functions.

The best example are characters…
You create character with movement, 100 hp, jump, shooting etc… and all other child classes have these functions and stats… so why its useful?
Lets say you have 130 heroes like in league of legends, all have only changed skins and abilities and some variables, but all of them have same respawn timer (for example)… so in primary class you change respawn timer and its immediately changed on all others heroes… imagine that work setting 130x respawn timer on all heroes… inheritance have to do “re-useable” codes… very good it is :slight_smile:

indeed very good, just having trouble in making some function work and getting variables…
somehow i got the idea

to use same fnction of parents
i add event to the child then next to it is the call parent function node…

so if i want the child to have it’s own unique style of events, i call the event node then i remove call parent function and instead add the child’s custom version of the event…

so please correct me if i’m wrong…
in the tutorials, the call parent functions automatically appear, but mine, i have to manually add them to every event i have…

then for the variables, how do i access the parent’s variable?
what i did was show inherited variables, then i just dragged the variable to the graph…
is that correct?

You’re doing everything correctly.

If you don’t need to add any functionality to the parent’s function for a child however you don’t need to even place it in the graph. When you do so you are overriding the original function so you have to call the parent’s function in order to get that functionality. If you don’t place it on the graph it will call the parent’s function by default. Just to save you a little time.