Expose c++ class to blueprint, where is my error?

It looks like you have 2 class names. VROPHOBIAV3_API should be removed.

Hello everyone,

I’m trying to expose the following to blueprint. It compiles, but when I right click on my class, the “Create blueprint class based on …” is not available. What do I do wrong? Thank you!

My .h

#pragma once

#include "Object.h"
#include "FileHelpers.h"
#include "FileLoaderReader.generated.h"

/**
 * 
 */
UCLASS()
class VROPHOBIAV3_API UFileLoaderReader :  UObject
{
	GENERATED_BODY()
	
:
	static bool VerifyOrCreateDirectory(const FString& TestDir);

	UFUNCTION(BlueprintCallable, Category = "Load/Save Text File")
		bool WriteToFile(FString Path, FString FileName, FString TextToSave, bool AllowOverwriting);

	UFUNCTION(BlueprintCallable, Category = "Load/Save Text File")
		bool ReadFromFile(FString PathToFile, FString FileName, FString& Result);
	
	
};

And the CPP

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

#include "VRoPhobiaV3.h"
#include "FileLoaderReader.h"


//If this function cannot find or create the directory, returns false.
bool UFileLoaderReader::VerifyOrCreateDirectory(const FString& TestDir)
{
	// Every function call, unless the function is inline, adds a small
	// overhead which we can avoid by creating a local variable like so.
	// But beware of making every function inline!
	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

	// Directory Exists?
	if (!PlatformFile.DirectoryExists(*TestDir))
	{
		PlatformFile.CreateDirectory(*TestDir);

		if (!PlatformFile.DirectoryExists(*TestDir))
		{
			return false;
			//~~~~~~~~~~~~~~
		}
	}
	return true;
}

bool UFileLoaderReader::WriteToFile(FString Path, FString FileName, FString TextToSave, bool AllowOverwriting)
{
	VerifyOrCreateDirectory(Path);

	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

	// CreateDirectoryTree returns true if the destination
	// directory existed prior to call or has been created
	// during the call.
	if (PlatformFile.CreateDirectoryTree(*Path))
	{
		// Get absolute file path
		FString AbsoluteFilePath = Path + "/" + FileName;

		// Allow overwriting or file doesn't already exist
		if (AllowOverwriting || !PlatformFile.FileExists(*AbsoluteFilePath))
		{
			FFileHelper::SaveStringToFile(TextToSave, *AbsoluteFilePath);
			return true;
		}
	}
	return false;
}

bool UFileLoaderReader::ReadFromFile(FString PathToFile, FString FileName, FString& Result)
{
	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

	// CreateDirectoryTree returns true if the destination
	// directory existed prior to call or has been created
	// during the call.
	if (PlatformFile.CreateDirectoryTree(*PathToFile))
	{
		// Get absolute file path
		FString AbsoluteFilePath = PathToFile + "/" + FileName;

		// Allow overwriting or file doesn't already exist
		if (PlatformFile.FileExists(*AbsoluteFilePath))
		{
			FFileHelper::LoadFileToString(Result, *AbsoluteFilePath);
			return true;
		}
	}
	return false;
}

I removed VROPHOBIAV3_API, didn’t do much good.

But adding “Blueprintable” to UCLASS() is working :slight_smile:

thank you!

Sounds like the exact right solution – According to the documentation on Class Specifiers, the Blueprintable specifier “Exposes this class as an acceptable base class for creating Blueprints.” Without it you won’t be able to create blueprints based on your class.

As a side note, the VROPHOBIAV3_API isn’t actually a second class name in this case. It is instead a macro used by the build system. You can find more information about the macro here or the build system here.