Set variables of parent

Hey guys,

I’ve got a Character class that inherits from another Character class. Like this:
Parent: LandCharacter
Child: Unicorn

In the parent class LandCharacter I’ve got a few variables.

51620-parentvariables.jpg

Now, I want to set these MaxWalkSpeed and MaxRunSpeed of the LandCharacter from the child Unicorn class.

So I call the desired variables in the child class and set them.

For a test I’ve printed them in both the LandCharacter and Unicorn class, when printing them from the Unicorn class they show up correctly. When printing from the Landcharacter they are still empty.

What am I doing wrong, why are they still empty in the parent class? Thanks

1 Like

When you change the value of a var into the child blueprint you will change that value only in that class.

51636-asd.gif

Like this, your parent class is “Figure”, “Cicle” and “Rectangle” are the child. If you change the value in the “Circle” class, that value will be only there, but if you change the value into “Figure” class then all the child will be have that value. Hope you understand what i’m trying to say.

Davide.

Ah, yes of course how silly of me. Thank you for reminding me.
Is there a way to fill the variables of the parent from within the child class?

Not that i know. By The way its unlogical do something like that. It should be the opposite. You set a default value into your parent blueprint, and then you change the value for each child you have. The parent should be the general class, and a child must not change the parent.

I realize that, I do. But the thing is that each of animals should have their own walking/running speed.

I’m gonna take another hard look on how I’m deriving my classes. Thank you for your help!

So I just solved this one since I really wanted to push variables from the child to it’s parent. For the people who want to do this in the future:

  1. In the parent class, create a new function with parameters to receive variables.
  2. Call that function in the child class and pass the variables as parameters.

I don’t know if this is new since the initial post, but a better option, use the Class Defaults panel:

Alternatively, show the inherited variables: