Creating a Blueprint Member Variable with the Same Name as a Variable in the Parent Class Causes Weird Behavior

First, I think the editor should not allow a user to give a blueprint member variable the same name as a member variable in a class which the blueprint inherits from. However, given than Engine v4.12 does allow it, some weird stuff can happen as a result. To reproduce one such error, do the following

  1. Create New Project > C++ (not blueprint) > Third Person

  2. Create a blueprint which inherits from actor.

  3. Create a member variable in the blueprint named “lifespan” of type float

  4. Note that the actor class already has a member variable named lifespan. Thus, creating a “lifespan” member variable in the blueprint is weird. Hopefully future versions of the Engine won’t allow it.

  5. Next, in the details window pane, try to set the lifespan’s default value to 5. Save and compile, The defualt will get reset to zero.

  6. Rename the blueprint variable from
    “lifespan” to something which
    doesn’t conflict with the name of
    parent (actor) class member variable.

  7. Now change the default value to 1000, save, and compile. It will not revert back to zero.

  8. Run the game where there is an
    instance of the blueprint in your
    level. The instance will be destroyed
    after 5 seconds. This is because
    we have managed to overwrite the
    default value for the lifespan
    member variable inherited from the actor class
    by temporarily creating a variable
    of the same name in a blueprint
    which inherited from the actor class.

  9. To check, you can edit the blueprint event graph so that on every tick getLifespan() is called, and gets printed to the screen. You’ll see it counting down: 5, 4.4733838, etc… down to zero.

Hi Irmis Turodan,

Thank you for letting us know about this. I ran some tests and was able to see the behavior that you described. I have entered UE-39930 to have this investigated further.