Property Setter is not getting called

I am trying to set up actor teams for use with the AI Perception system, where a base class derived from ACharacter exposes the team as an FName and uses a setter SetTeamName to turn that into an FGenericTeamId. I declare the setter function and variables in my header as:

protected:

UFUNCTION(BlueprintCallable)
void SetTeamName(const FName& name);

UPROPERTY(EditAnywhere, Setter, meta = (GetOptions = "GetTeamNames"))
FName TeamName;

UPROPERTY(VisibleAnywhere)
FGenericTeamId Team;

While the GetOptions works fine, properly displays my set of viable team FNames and appears to set TeamName, it does so directly and does not go through SetTeamName. I have verified this by running the game in debug through Visual Studio and setting a breakpoint in the setter, which never hits.

I’ve tried this with the UFUNCTION macro, without it, with explicitly setting the Setter method, with and without a Getter, and changing the method signature to use an FName directly instead of a const reference. Any help would be appreciated!

Edit:

To be more specific, I want the setter to be called when setting the value in the Details pane:

The Team Name dropdown populates correctly, but it directly sets the FName in the class instead of calling SetTeamName

public:

	UFUNCTION(BlueprintCallable)
	void SetTeamName(const FName& name);

	UFUNCTION(BlueprintPure)
	FName GetTeamNames();

protected:	
	UPROPERTY(EditAnywhere, Setter, meta = (GetOptions = "GetTeamNames"))
	FName TeamName;

cpp

void AMyActor::SetTeamName(const FName& name)
{
	GEngine->AddOnScreenDebugMessage(1, 1, FColor::Orange, TEXT("Setting name "));
	TeamName = name;
}

FName AMyActor::GetTeamNames()
{
	return TeamName;
}

Triggered

image

In action

in game


So internal logic is triggered (where you can sanitize it, and format the text as needed)

@3dRaven thank you for replying, I should have been more specific. I want the Setter to be called when I set the value through the Details pane specifically, not through a Blueprint. For example:

The Team Name dropdown populates correctly and sets the underlying value, but I want it to call SetTeamName so that it updates Team ID as well.

Well that is not through the setter and getter function :wink:

Look into PostEditChangeProperty

OFC you need to modify it to call the chain of functions you require based on the team variable.

I guess I was under the impression that Setter was different from BlueprintSetter, as the latter seems more explicit to blueprints. I had completely forgotten about PostEditChangeProperty, that probably is the only way to do what I want. Thanks!

1 Like

Don’t forget to wrap it in an editor macro and call it’s super (parent) implementation at some point or you might get an error

#if WITH_EDITOR
void AMyClass::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
{

// your code here

Super::PostEditChangeProperty(PropertyChangedEvent); // calls parent default change code
}
#endif

This stuff is editor only code so it has to be isolated with the if block WITH_EDITOR

1 Like