How to use normal C++ classes in UE4

I was wondering how to use normal C++ classes in UE4 code.

Simple normal C++ example:

class Upgrade
{
public:
	void IncrementMoney();
private:
	int Money = 1;
};

int main()
{
	Upgrade MyUpgrade;

	while (true)
	{
		MyUpgrade.IncrementMoney();
	}

}

void Upgrade::IncrementMoney()
{
	Money++;
	cout << "Value: " << Money << endl;
}

I’ve been stuck trying to implement something like this in Unreal Engine, I tried using USTRUCTS, which worked up till the point that I need UFUNCTIONS, and then it all fell apart. I’ve been stuck on this issue for a while.

I’m trying to create a base class for upgrades, each costing a different price etc, which is why I’m trying to use
classes.

Thank you, sorry for a possibly noob question.

You can use normal C++ classes in UE4, so long as you don’t want to expose it to the engine in any way, including memory management (eg. garbage collection and reflection), and blueprints exposure.

To expose it to the engine you’ll need to add the Unreal Header decorators on the line above each class, member function, and member variable. UCLASS(…), UFUNCTION(…), and UPROPERTY(…) respectively.

Take a look at the introduction to c++ in the documentation for examples of how to use these and what goes inside the parenthesis (Programming with C++ | Unreal Engine Documentation)

Why would you want to use normal cpp class ? Unreal comes with great advantage of memory management if you use any child of UObject ( + UFunctions, + UProperties … )

You can still create your own child of AActor and create Upgrades there, but it will limit your ability to expose this Upgrade class into blueprint.

What does this upgrade do ? Is it unlockable property on player? Is it pickable object in scene ?

You can not expose normal (aka non-UObject) classes, but you can expose structs which can contain functions… but you can not expose functions in struct, you need to use static functions then on some UObject class