Download

UFUNCTION doesn't work with classes based on NONE class?

Hi, i made c++ class based on NONE class in the list of editor and wrote these simple lines in it

SteamClass.h contain


#pragma once

/**
 * 
 */
class TESTSTEAMSIMPLE_API SteamClass
{
public:
	SteamClass();
	~SteamClass();

	UFUNCTION(BlueprintCallable, category = Steam)
	void happy_SteamInit();
};


SteamClass.cpp contain


#include "TestSteamSimple.h"
#include "Engine.h"
#include "SteamClass.h"

SteamClass::SteamClass()
{
}

SteamClass::~SteamClass()
{
}

void SteamClass::happy_SteamInit()
{
	UE_LOG(LogTemp, Warning, TEXT("test"));
	/*
	if (!SteamAPI_Init())
	{
	UE_LOG(YourLog, Warning, TEXT("steam SteamAPI_Init failed"));
	}
	*/
}

But when i open level blueprint and tryes add call to happy_SteamInit it isn’t exist in the list even with “conext sensetivity” checked off

When i added UCLASS(), GENERATED_UCLASS_BODY() and renamed class to USteamClass (as stated in compile errors in VS) i got next code:

SteamClass.h contain


#pragma once

/**
 * 
 */
UCLASS()
class TESTSTEAMSIMPLE_API USteamClass : public UObject
{
public:
	USteamClass();
	~USteamClass();

	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, category = Steam)
	void happy_SteamInit();
};


SteamClass.cpp contain


#include "TestSteamSimple.h"
#include "Engine.h"
#include "SteamClass.h"

USteamClass::USteamClass()
{
}

USteamClass::~USteamClass()
{
}

void USteamClass::happy_SteamInit()
{
	UE_LOG(LogTemp, Warning, TEXT("test"));
	/*
	if (!SteamAPI_Init())
	{
	UE_LOG(YourLog, Warning, TEXT("steam SteamAPI_Init failed"));
	}
	*/
}

i get couple error during complile

Error 2 error code: 2 D:\ue4\TestSteamSimple\Intermediate\ProjectFiles\Error TestSteamSimple
Error 3 error MSB3073: The command ““D:\ue4\engine\Epic Games\4.4\Engine\Build\BatchFiles\Build.bat” TestSteamSimpleEditor Win64 Development “D:\ue4\TestSteamSimple\TestSteamSimple.uproject” -rocket” exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 TestSteamSimple
4 IntelliSense: identifier “FWindSourceSceneProxy” is undefined d:\ue4\engine\Epic Games\4.4\Engine\Source\Runtime\Engine\Classes\Components\WindDirectionalSourceComponent.h 20 2 TestSteamSimple
5 IntelliSense: identifier “FOnSelectedLevelsChangedEvent” is undefined d:\ue4\engine\Epic Games\4.4\Engine\Source\Runtime\Engine\Classes\Engine\World.h 1929 2 TestSteamSimple
6 IntelliSense: no instance of constructor “FReadSurfaceDataFlags::FReadSurfaceDataFlags” matches the argument list d:\ue4\engine\Epic Games\4.4\Engine\Source\Runtime\Engine\Public\UnrealClient.h 55 92 TestSteamSimple
7 IntelliSense: no instance of constructor “FReadSurfaceDataFlags::FReadSurfaceDataFlags” matches the argument list d:\ue4\engine\Epic Games\4.4\Engine\Source\Runtime\Engine\Public\UnrealClient.h 63 87 TestSteamSimple
8 IntelliSense: identifier “FMeshBatchElement” is undefined d:\ue4\engine\Epic Games\4.4\Engine\Source\Runtime\ShaderCore\Public\VertexFactory.h 488 131 TestSteamSimple
9 IntelliSense: no default constructor exists for class “UObject” d:\ue4\TestSteamSimple\Source\TestSteamSimple\SteamClass.cpp 8 1 TestSteamSimple
10 IntelliSense: expected an identifier d:\ue4\TestSteamSimple\Source\TestSteamSimple\SteamClass.h 15 2 TestSteamSimple

The goal i try to achieve is custom C++ function to run SteamAPI_Init() function and activate steam

You can’t use those types of constructors in uobjects in 4.5.

4.6 is meant to allow them, I think. But for now you need to change your constructor to


SteamClass::SteamClass(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}


Also remove the definition of it from the .h file. You should also remove the deconstructor completely.

SteamClass.h contain now


#pragma once

UCLASS()
class TESTSTEAMSIMPLE_API USteamClass : public UObject
{
	
public:

	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, category = Steam)
	void happy_SteamInit();
	
};

SteamClass.cpp contain now


#include "TestSteamSimple.h"
#include "Engine.h"
#include "SteamClass.h"

SteamClass::SteamClass(const class FPostConstructInitializeProperties& PCIP): Super(PCIP)
{
}

void USteamClass::happy_SteamInit()
{
	UE_LOG(LogTemp, Warning, TEXT("test"));

	//if (!SteamAPI_Init())
	//{
	//UE_LOG(YourLog, Warning, TEXT("steam SteamAPI_Init failed"));
	//}

}

Code won’t compile with couple of errors:

Error 2 error C4610: class ‘USteamClass’ can never be instantiated - user defined constructor required d:\ue4 eststeamsimple\source eststeamsimple\SteamClass.h 16 1 TestSteamSimple
Error 3 error C2653: ‘SteamClass’ : is not a class or namespace name D:\ue4\TestSteamSimple\Source\TestSteamSimple\SteamClass.cpp 7 1 TestSteamSimple
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int D:\ue4\TestSteamSimple\Source\TestSteamSimple\SteamClass.cpp 7 1 TestSteamSimple
Error 5 error C2550: ‘SteamClass’ : constructor initializer lists are only allowed on constructor definitions D:\ue4\TestSteamSimple\Source\TestSteamSimple\SteamClass.cpp 8 1 TestSteamSimple
Error 6 error C4508: ‘SteamClass’ : function should return a value; ‘void’ return type assumed D:\ue4\TestSteamSimple\Source\TestSteamSimple\SteamClass.cpp 9 1 TestSteamSimple
Error 7 error : Failed to produce item: D:\ue4\TestSteamSimple\Binaries\Win64\UE4Editor-TestSteamSimple.pdb D:\ue4\TestSteamSimple\Intermediate\ProjectFiles\ERROR TestSteamSimple
Error 8 error MSB3073: The command ““D:\ue4\engine\Epic Games\4.4\Engine\Build\BatchFiles\Build.bat” TestSteamSimpleEditor Win64 Development “D:\ue4\TestSteamSimple\TestSteamSimple.uproject” -rocket” exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 TestSteamSimple

Did i wrote code wrong somehow?

This seems wrong.

Oh, right forget add U there as well, but even with it still doesn’t work with totaly unclear error description :frowning:

Error 2 error code: 2 D:\ue4\TestSteamSimple\Intermediate\ProjectFiles\Error TestSteamSimple
Error 3 error MSB3073: The command ““D:\ue4\engine\Epic Games\4.4\Engine\Build\BatchFiles\Build.bat” TestSteamSimpleEditor Win64 Development “D:\ue4\TestSteamSimple\TestSteamSimple.uproject” -rocket” exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 TestSteamSimple
4 IntelliSense: explicit type is missing (‘int’ assumed)
this refer to UCLASS() line and select this word

5	IntelliSense: expected a '{'	

this refer to class word on class line declaration
class TESTSTEAMSIMPLE_API USteamClass : public UObject

6	IntelliSense: expected an expression	

this refer to public: word

Also vs emphasizes red few places:

  1. ::USteamClass in line

USteamClass::USteamClass(const class FPostConstructInitializeProperties& PCIP): Super(PCIP)

with error void USteamClass::USteamClass() +2 overloads error: no instance of overloaded function “USteamClass::USteamClass” matches the specified type

  1. on the same line between & PCIP, error says: expected an identifier

  2. same line : after & PCIP), error says expected a ‘{’

  3. in class declaration GENERATED_UCLASS_BODY, error says expected ad identifier

Tryed add


USteamClass::USteamClass(const class FPostConstructInitializeProperties);

to class declaration to solve error №1, but it didn’t help and linker still whine on at class constructor definition

class declaration in this case


class TESTSTEAMSIMPLE_API USteamClass : public UObject
{
	
	
public:

	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, category = Steam)
	void happy_SteamInit();
	
	USteamClass::USteamClass(const class FPostConstructInitializeProperties);
};

You do not have to add the ‘USteamClass::USteamClass(const class FPostConstructInitializeProperties);’ declaration, thats done by the GENERATED_UCLASS_BODY() macro.

hm, okay, but how about other thing? here is link to this simple template project, you can try compile it as well, if it work, we can try find out what’s the difference (maybe some default vs settings or any other !@#$%^ as usually xD)

For size reduction removed folder “Content”, if so you can move if from any other templat project on your PC

You also need to add


#include "SteamClass.generated.h"

to your SteamClass.h file. See if that helps.

Tyvm, it helped, but now i have futher problem. In level blueprint i made “begin play” event node and my function call, but when i press cimpile blueprint appers error

BlueprintEditorCompileResults:Error: Error This blueprint (self) is not a SteamClass, therefore ’ Target ’ must have a connection

and my function node somehow contain blue Target pin without any wires and “self” as constant parameter. So is here any way i can reference this pin with my class or just remove it?

Will make separate thred for this last error, topic’s problem solved.