Hi peeps,
First time coding some C++ code, I’m currently trying to create a simple way to project a box to my screen. I’m therefore trying to make a function that takes in a UBoxComponent and gives me a FIntRect that surrounds my box.
Unfortunately, I am having trouble with the definition of the function with the USTRUCT FIntRect, the compiler gives me a “Bad function definition” in my .h that I don’t really understand.
Here are the codes :
.h
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Core/Public/Math/IntRect.h"
#include "BlueprintFunctions.generated.h"
/**
*
*/
UCLASS()
class INTERSTELLARQUEST_API UBlueprintFunctions : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category="Custom functions")
static USTRUCT *IntRect boxProjection();
};
I also have a" Use of undeclared identifier ‘UBlueprintFunctions’" and “Unknown type name ‘USTRUCT’” showing in my cpp file in Xcode that i can’t explain.
If that is the case then you might be missing some core includes. Another thing, you might need to get rid of the & sign on the return value, the & is more efficient because it’s a direct reference to what you’ve created (instead of a copy), but it might get garbage collected, so you have to see if you run into problems, just take it out.
FIntRect is a structure from Unreal Engine, so you need to have includes that tell the compiler where to find the definition for it. Worst case you can try to include it manually like:
I have included this library already, and it compiled fine if I used the FIntRect within the function (as long as it’s not in the header following the UFUNCTION declaration).
This compiles :
.h
UFUNCTION(BlueprintCallable, Category="Custom functions")
static int boxProjection();
.cpp
int UBlueprintFunctions::boxProjection()
{
FIntRect test = FIntRect(1,1,2,2);
return 1;
}
I figured it’s something to do with those two posts but I didn’t get it to work yet.
I checked engine source code and FIntRect is a C++ type. Not exported as BlueprintType.
You won’t be able to use it as a UPROPERTY inside your own module.
You can however copy FIntRect code from IntRect.h and .cpp to your own code module and attach USTRUCT(BlueprintType) to it.