Could someone make a tutorial on how to add a Global Class & expose it to Blueprints?

So I’m 100% new to the Unreal Engine, and I’d like to create a C++ class using the “None” option, as shown in this picture…

I chose “None”, because the class I am implementing will not be spawned in game (at least not visually). It should be a Global object, I don’t need to be able to reference the variable holding the object globally, I only need its lifetime to exist until the game ends (I also need to find out how to do this).

The purpose of this custom class is to work as a networking interface for a 3rd party server that I’ve developed, did I choose the correct C++ class type for this? I think I did, but a more seasoned Unreal Developer may know better. In other words I need to be able to call at it to send data to the server, and then I need it to be able to call another interface (not yet made) that handles responding to server messages and applying their functionality/instructions. In my own first example I’ve created a UMG Login Screen, and when the user clicks “Login” I want it to create an instance of this new Class that lives until the client disconnects from the game. However, when I go to the Login Button onClicked event in BluePrints the class is no where to be found.

When I try to make the Class & expose it to Blue prints, I get errors… These ones to be exact.
d38dd5d73c.png

From this I’m understanding that I need to inherit from UObject, but why…? Even if I do inherit from UObject, I still get these errors…
8b3a2c3c6b.png

This is my code…
TestClass.h



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

#pragma once

/**
 * 
 */
UCLASS(BlueprintType, Blueprintable)
class GAMECLIENT_API TestClass : public UObject
{
public:
	TestClass();
	~TestClass();
};


TestClass.cpp



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

#include "GameClient.h"
#include "TestClass.h"

TestClass::TestClass()
{
}

TestClass::~TestClass()
{
}


Hey OP, I’m going to move this to the C++ forum, I think you’ll get better traction on your question there.

As for your problem, I’m not totally sure but you may need to have an Engine.h include somewhere.

If you’ve got ‘OtherCompilationError’ in the error list, you should look at the Output/Debug window for more details. Paste those here!

Unreal Engine has an object which exist during all the existence of the instance, its name is GameInstance.

Once you create your GameInstance, you need to declare it inside your Project Settings, Maps & Mode and set your GameInstanceClass.

You are free to declare all you need inside your Custom GameInstance, but you can also create a UObject and create it inside the constructor, you need to use:


 CreateDefaultSubobject<T>(TEXT("NameOfYourObject") 

else you can also override the Init() function and simply use:


NewObject<T>(this) //Don"t forget the 'this' pointer, if you didn't set it your object will be garbage collected

Note: Don’t use NewObject<T>() inside a constructor.

After it’s easy to access the GameInstance, any Actor have an GetGameInstance Node, cast to your custom one and get what you need (if it’s your UObject don’t forget to add BlueprintType to the UCLASS() declaration).

Hey, maybe this is what you want

Is this?