Error while using Server function

Hi, I am creating a Server function in an Actor Component that is to be called from blueprint like this

UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Health")
void ServerDegenerateHealth(UCurveFloat* CurveFloat, AActor* DamagedActor, UDamageType* DamageType, AController* InstigatedBy,
			                AActor* DamageCauser, float Rate = 2.f, bool CanEventBeStopped = true);

I have defined in cpp like this -

void UGenericHealthComponent::ServerDegenerateHealth_Implementation(UCurveFloat* CurveFloat, AActor* DamagedActor, 
	                                                                UDamageType* DamageType, AController* InstigatedBy,
	                                                                AActor* DamageCauser, float Rate, bool CanEventBeStopped)

But I am getting error -

error C2511: 'void UGenericHealthComponent::ServerDegenerateHealth(UCurveFloat *,AActor *,const UDamageType *,AController *,AActor *,float,bool)': overloaded member function not found in 'UGenericHealthComponent'

 'void UGenericHealthComponent::ServerDegenerateHealth_Implementation(UCurveFloat *,AActor *,UDamageType *,AController *,AActor *,float,bool)': overloaded member function not found in 'UGenericHealthComponent'
1>  C:\Users\BlackHawk\Documents\Unreal Projects\HealthProject\Plugins\GenericHealthFramework\Source\GenericHealthFramework\Public\GenericHealthComponent.h(85): note: see declaration of 'UGenericHealthComponent'

I’m not sure if it’s a must to have but I think you’re missing the WithValidation in the UFUNCTION macro, once you have that added you also need to add in cpp ServerDegenerateHealth_Validate(args…) { return true; }

Edit:
Yeah I think you have to have a validate I quote from this page:

A more recent change was added to UHT to require client->server RPC’s to have a _Validate function. This is to encourage secure server RPC functions, and to make it as easy as possible for someone to add code to check each and every parameter to be valid against all the known input constraints.

Thanks for the help but I have used initially with WithValidation only. I was having same error.

Strangely If I don’t use UDamageType in the function then it works fine. I don’t know whether it’s a feature or a bug.

//This works
UFUNCTION(Server,Reliable,BlueprintCallable, Category = "Health")
		void ServerDegenerateHealth(UCurveFloat* CurveFloat, AActor* DamagedActor,
			AController* InstigatedBy, AActor* DamageCauser, float Rate, bool CanEventBeStopped);
//This doesn't
UFUNCTION(Server,Reliable,BlueprintCallable, Category = "Health")
		void ServerDegenerateHealth(UCurveFloat* CurveFloat, AActor* DamagedActor,
			AController* InstigatedBy, AActor* DamageCauser, float Rate, bool CanEventBeStopped,UDamageType* type);

Any Idea?

It could be that it’s not defined, in your header file add class like this:
…, class UDamageType* DamageType, …

and in C++ include GameFramework/DamageType.h

It was my initial guess but I had already tried that and got the same error.

Replace UDamageType* with TSubclassOf< class UDamageType >

Edit:
Ok adding const seems to work as well
const class UDamageType* DamageType

1 Like

oh ok, Thanks I will verify. I don’t get the reason behind it. I am not able to figure it out : ( Is this a bug ?

I just tried it and it worked for me. I don’t think it’s a bug, have you tried it or not yet ?
Make sure you add the WithValidation and _validate function, or you can temporarily make it a client function just to test.

I have tried and it works. Although in my production code I will be adding cheat protection, but without Validation also it works. So don’t know if it’s compulsory

	UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Health")
		void Foo(const class UDamageType* DamageType);

	void Foo_Implementation(const class UDamageType* DamageType)
	{

	}

Interesting, I was also able to compile without the WithValidation, perhaps something changed in recent versions because I remember this was something required to have and you can’t compile without it.

Yes, anyways thanks for the help. I think I can continue with my work.

You’re welcome, good luck.