I’ve got some struct definitions for both C and C++ in one header, and using #if defined __cplusplus doesn’t seem to work with the unreal header tool.
My code looks like this:
// Atmos.h
#if defined __cplusplus || UE_GAME || UE_EDITOR || UE_SERVER
#pragma once
#include "Atmos.generated.h"
USTRUCT(Blueprintable)
struct FGases
{
GENERATED_BODY()
...
};
USTRUCT()
struct FAtmosVoxel
{
GENERATED_BODY()
...
};
#else
typedef struct
{
...
} AtmosVoxel;
#endif
and trying to include it produces an error that the C++ structs are not USTRUCT types. When I comment out the preprocessor directives it works fine.
Do #ifdefs not work for the unreal header tool or am I doing something wrong? I read in another question that they were fixed
DennyR
(DennyR)
August 7, 2016, 4:10pm
2
According to this answerhub post , it should work. Never used it in Unreal though, so I can’t tell.
You might have another bug in your code though.
You are using USTRUCT(Blueprintable)
what you want is USTRUCT(BlueprintType)
though.
Blueprintable exposes a class to BP allows subclassing of it. Unreal does not support subclasses of UStructs in BP (or anywhere for that matter).
You don’t need the defined keyword. If it is not defined it is falsy.
You are doing the equivalent of this in the macro world:
if (I < 5 || 10 || 17)
This is an illegal statement. The code you want is:
#if __cplusplus || UE_GAME || UE_EDITOR || UE_SERVER
trojanfoe
(trojanfoe)
August 8, 2016, 12:54pm
6
Isn’t __cplusplus
always defined, so that’s the equivalent of #if 1
. What is this #if
statement supposed to do?
I’m including this header in OpenCL C, I want to place both struct types in one file for convenience
I looked through the Header Tool source and it looks like it doesn’t parse any if/ifdefs for C++, so I just wrote a BlueprintType wrapper struct in another file for the C/C++ struct