Search code examples
c++unreal-engine5

Unreal Engine 5.1.1 UFUNCTION not working properly. Code does not compile


Working with Unreal Engine 5.1.1 and Visual Studio Community 2022 17.2.6. Trying to expose a C++ function to a UE blueprint. When adding the UFUNCTION macro above the function in the header, the C++ does not compile in VS with the compile error:

Found 'end of type' when expecting an identifier

on the function line, line 25.

Code:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Components/StaticMeshComponent.h"
#include "MazeGenerator.generated.h"

UCLASS()
class MINOTAUR_API UMazeGenerator : public UActorComponent
{
    GENERATED_BODY()

public: 
    UPROPERTY(EditAnywhere)
    int mX;
    UPROPERTY(EditAnywhere)
    int mY;

    // Sets default values for this component's properties
    UMazeGenerator();

    UFUNCTION(BlueprintCallable)
    void LoadVoxels(std::string);

private:

    UStaticMesh** maze_voxels;
};

Have looked for answers here and on youtube and have not found anything matching my question exactly, mostly stuff about having an erroneous semicolon at the end, and people successfully doing this in a different context of course. This probably won't involve the UE editor itself since it is really a visual studio compile error.


Solution

  • BlueprintCallable functions can have only some specific parameter types and return types: UObjects or UStructs marked Blueprintable (that includes almost any frequently used object type, such as AActor inheriting types, actor components, textures/materials/essentially anything else you can find the content browser), bools, numbers in float/int32/int64, text in FString/FText/FName, arrays/sets/maps of the types mentioned above as well, some delegates.

    Outside of that, no other types can be used, because the Blueprint system wouldn't know how to make/display pins for such a type in the graph. For example:

    UFUNCTION(BlueprintCallable)
    void DoSomething(bool* BoolPointer);
    

    won't compile. Same goes for std::string or any other C++ standard library type.

    You are free to use standard library types if they don't need to cross over to the Blueprint world. However, if you want to use a string in any Unreal specific code, it's best to use FString. You can convert an std::string to FString easily, please see this Unreal forum post.