Why is my c++ function a Pure blueprint function

I have been trying to make my function available to use in my blueprints as an overridable function. I couldn’t see it in my list of overridable functions, so I tried to call it and it appeared as a pure function. I don’t know why this is happening.

My function in my header file is:

UFUNCTION(BlueprintCallable, Category = "AIVariables | Character")
		void GetPerceptionLocRot(FVector &OutLocation, FRotator &OutRotation) const;

My function in my c++ file is:

void AAI_Char::GetPerceptionLocRot(FVector &OutLocation, FRotator &OutRotation) const
{
	OutLocation = GetActorLocation() = FVector(0, 0, 50);
	OutRotation = GetActorRotation();
}

I can’t see anything in this code that would make it a pure function, but then again, I am new to c++ and it’s relationship with Blueprints.

EDIT: When I hover near the UFUNCTION in Visual Studio, it displays this message:

250472-ufunction-issue.png

1 Like

You can ignore the message Visual Studio is showing since this is false positive.

In order to override the function in your Blueprint, tag the function as BlueprintNativeEvent and create another function with the following signature

virtual void GetPerceptionLocRot_Implementation(FVector &OutLocation, FRotator &OutRotation);

You then move the implementation of your function to this one. Internally, in your C++ class you can keep calling GetPerceptionLocRot() regularly.

You can check the sample Extend and Override C++ with Blueprints for more information on how to proceed with this.

Const functions are always considered pure by the Unreal Build tool. Since they are not supposed to modify the members of the class (except for mutable varaibles, which you should use exceptionally), there is no need for the execution pin to go throught them.

1 Like

I did not see the const at the end of the function. That is a very good observation.

I tried this, and removed the virtual in front of the function, as it gave a compiling error. The new error is:

You have to remove the const from GetPerceptionLocRot(). Check @Bariudol answer, I did not notice the const there.

New Error:

I altered my code as well. My header file:

UFUNCTION(BlueprintNativeEvent, Category = "AIVariables | Character")
		void GetPerceptionLocRot(FVector &OutLocation, FRotator &OutRotation);
		void GetPerceptionLocRot_Implementation(FVector &OutLocation, FRotator &OutRotation);

	void GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const override;

And my C++ file is:

void AAI_Char::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation)
{
	GetPerceptionLocRot(Location, Rotation);
}


void AAI_Char::GetPerceptionLocRot(FVector &OutLocation, FRotator &OutRotation)
{
	OutLocation = GetActorLocation() = FVector(0, 0, 50);
	OutRotation = GetActorRotation();
}

Have you tried changing your *.h to be “virtual void Name (Parameters) [override];”. I am away from my game laptop but if you follow the construct of the BeginPlay syntax you should get the same results.

I am assuming you already have a UFUNCTION defined above the declaration.
UFUNCTION(BlueprintCallable)
virtual void FunctionName(int32 Parameter);

If you look at the first error when building AI_Char.cpp you will see that the function GetActorEyesViewPoint was not found in the base class, or it was not declared as virtual in the base class.

Another thing, the implementation of GetActorEyesViewPoint does not have the const qualifier. Always remembers that declaration and definition of a function needs to match. Either remove the const or add one in the Cpp file

First: Add BlueprintNativeEvent to the UFUNCTION(), then in the .cpp, rename the definition to AAI_Char::GetPerceptionLocRot_Implementation. You should keep the BlueprintCallable specifier there also.

Then, you should add BlueprintPure=false to the UFUNCTION(), it will force the compiler to include the Execution Pins again.

This can be important because BlueprintPure outputs are not cached (they are re-evaluated for every execute pulse). The CPP compiled method will also retain the optimizations the compiler can use with const methods.

You mean Unreal Header Tool ;p

@anonymous_user_f5a50610 you are right. Thanks for the correction.

Okay, I tried your way and altered my code to:

header:

UFUNCTION(BlueprintCallable, BlueprintPure=false, BlueprintNativeEvent)
	void GetPerceptionLocRot(FVector & OutLocation, FRotator & OutRotation) const;
	void GetPerceptionLocRot_Implementation(FVector & OutLocation, FRotator & OutRotation) const;

void GetActorEyesViewPoint(FVector & Location, FRotator & Rotation) override;

};

cpp:

void AAI_Char::GetPerceptionLocRot(FVector &OutLocation, FRotator &OutRotation) const
{
	OutLocation = GetActorLocation() = FVector(0, 0, 50);
	OutRotation = GetActorRotation();
}

void AAI_Char::GetPerceptionLocRot_Implementation(FVector &OutLocation, FRotator &OutRotation) const
{
	OutLocation = GetActorLocation() = FVector(0, 0, 50);
	OutRotation = GetActorRotation();
}


void GetActorEyesViewPoint(FVector& Location, FRotator& Rotation)
{
	GetPerceptionLocRot_Implementation(Location, Rotation);
}

I had to define the GetPerceptionLocRot twice to fix a compiler issue.

My error this time is:

I know for definite that this class is inheriting from the base class character, yet it is saying that the override isn’t working. Please help

Alright, so you can remove the

void GetPerceptionLocRot_Implementation(FVector & OutLocation, FRotator & OutRotation) const;

declaration from the header file. It’s implied you’re going to override it. (intellisense will probably complain, but it should work).

Second, remove the

void AAI_Char::GetPerceptionLocRot(FVector &OutLocation, FRotator &OutRotation) const

definition from the source (cpp) file, you only need the _Implementation version.

Third, for GetActorEyesViewPoint, you need to add the virtual and const keywords, so it looks like:

virtual void GetActorEyesViewPoint( FVector& OutLocation, FRotator& OutRotation ) const override;

And then, you need to completely rewrite the source (cpp) implementation to look like:

 void AAI_Char::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const
 {
     GetPerceptionLocRot(Location, Rotation);
 }

You don’t want to specifically call GetPerceptionLocRot_Implementation, because then any blueprint overriders wouldn’t get an opportunity to be used.

Let us know how you go!