How is the DisplayName UPROPERTY specifier supposed to work?

Hi!

In our project we’d like to use the “m_” prefix for member variables internally in our C++ code but when they’re exposed to Blueprint, that would be confusing to non-programmers. Searching a bit, I’ve found the DisplayName property specifier which sounds like exactly what we need: “Sets the display name for the property in the editor.”

So I declared my variable like this:

UPROPERTY( BlueprintReadOnly, Config, Category = CombatStats, DisplayName = "Critical Hit Chance" )
float m_criticalHitChance;

In the editor, it shows up as m_criticalHitChance.

Since DisplayName is listed under Valid Meta Properties, I then tried the following:

UPROPERTY( BlueprintReadOnly, Config, Category = CombatStats, meta=(DisplayName = "Critical Hit Chance") )
float m_criticalHitChance;

But this resulted in the variable not even turning up in the editor at all. Worse, if the variable was previously referenced in a Blueprint, the Blueprint will throw a compiler error and the following error message was printed to the log:

LogBlueprint:Warning: [CombatComponent_BP] CreatePinForVariable: ‘m_criticalHitChance’ variable not found. Base class was probably changed.

LogBlueprint:Warning: [compiler CombatComponent_BP] Warning Could not find a variable named “m_criticalHitChance” in ‘CombatComponent_BP_C’. Make sure ‘CombatComponent_BP_C’ has been compiled for Get m_criticalHitChance

Strangely, I just tried this again and can’t reproduce the second part. The variable always turns up but it’s still displayed as m_criticalHitChance.

So how do you change the editor display name of a variable declared in C++?

I’ve noticed that when defining DisplayName as Meta property, the displayed name does change, but only when viewing object instances in the World Outliner. That might be intended behavior (arguably, anyone editing the Blueprints should be knowledgeable enough to understand the difference) but it seems like it might be a source of confusion for users both querying a variable in a Blueprint and changing its value in the object instance.

In any case, that wasn’t what I expected from the description of the property (A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums), so at the very least the documentation should be clarified.

Also, see this old bug report for the property becoming unknown in the Blueprint: Using UPROPERTY( Meta = (DisplayName = "something") makes property _disappear_ - Programming & Scripting - Epic Developer Community Forums

This is a great question and one I’d like an answer to. Would be nice to strip out the prefixes from naming conventions and so forth in dropdowns and class pickers.