Forward declaration of argument doesn't work with UFUNCTION

So, annoyingly, the header tool chokes once again on a common feature of C++. This time it throws a compile error when trying to compile a UFUNCTION that takes a USTRUCT type that has been forward declared in the header file.


#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"

#include "StageUtilities.generated.h"

struct FStageParams; // Forward declaration

class UStageUtilities : public UBlueprintFunctionLibrary
	GENERATED_BODY() // <<<<< Error points to this line

	UFUNCTION(BlueprintPure, Category = "Stage")  // <<<<< Caused by this
	static FName GetLevelNameFromStageParams(const FStageParams params);


The compile errors are:

error C2079: 'Z_Param_params' uses undefined struct 'FStageParams'
error C2664: 'FName UStageUtilities::GetLevelNameFromStageParams(const FStageParams)' : cannot convert argument 1 from 'int' to 'const FStageParams'

Removing the UFUNCTION macro let’s it compile correctly, so it seems like it’s just a failure of the header tool to be able to recognize forward declarations, though if that were the case I feel like more people would have ran into this issue. So what’s the deal here? Why can’t it recognize the forward declaration? And what the hell is Z_Param_params?

Hello FakeEnema,

This would work without an issue if you were forward declaring a Class but with Structs, they don’t have the same two-pass parsing system that Classes use. This results in this occurring as the parameters for a UFunction need to be parsed. If using a struct, forward declaration won’t work for UFunctions.

Ahh, bummer, but thanks for the explanation. Guess I’ll have to just include the appropriate header then. Hopefully I don’t run into any cyclical dependencies in the future because of this.