Creating Non-Actor Objects

I learned that the actors belong to the level, so I want to create non-actor objects. because I want my objects never to destroy. The Objects I’ll create must not have SceneComponent. They’re not actor, only the objects I will use to manage the whole game. I want to create something out of the game world.

I usually don’t prefer to use GameFramework(GameMode etc.) and Blueprint.

For example, I’ll tell GameManager to load LoginLevel, when the game is loaded for the first time

class ClientManager : UObject 
{
    CLASS_NAME _myNetwork; //  my network library (using winsock/berkeley sockets)
    // To connect to server,create clients .. ...
} 

class MapManager : UObject
{
   MAP_OBJECT // holds NPCs, Characters in level.

   LoadLevel(); UnloadLevel();
}
class GameManager : UObject{ // It will store some game information and has some functions...}

When press the login button in the Login Level or a player is in teleportation zone in xxx_level, the loadmap function will be called.

Also I want my objects to have functions like tick, beginplay.

Let me briefly summarize the life cycle I want to create,

Engine->Call my objects functons->Call level actors functions

If these are impossible, could you give me alternative ways and advices?

For this use case you should make a custom GameInstance, and create your manager objects from there.

class MyGameInstance : public UGameInstance
{
 private: 
	UPROPERTY()
	UGameManager * GameManager ; 
    // UPROPERTY() is necessary to prevent from being garbage collected
}

You’ll also need to change the default GameInstance from Project Setting:

Edit->Project Settings->Maps & Modes->GameInstanceClass -> "MyGameInstance"

GameInstance don’t have Tick function, but you can achieve the same thing using a looping timer.

Could you explain the “Looping Timer” a little more?

And I have one more question.

There is a GameLoader widget. Let’s say we call these functions in sequence :

A()->B()->C()->D()

The game is working in the GameThread. When I change a widget of the GameLoader in the ‘A’ function (for example: Loading.Text = “Function ‘A’ is called!”), it won’t change until other functions are called, right?

I want it to render when A function called. Do I have to use one more thread? Are Widgets or UObjects thread-safe?

A(){
         Loading.Text = "...."
         RenderWidget()
         B()
}

Or Should I use Tick() and call functions in turn?

Tick()
{
if........

 First Frame Call A()  return
 Second Frame Call B() 
.....
....
}

It sounds like a very challenging and amateurish. What do you think about this?

Thanks.

By looping timer I mean set a Timer using TimerManager with the bLoop parameter set to true.

Here is the documentation of TimerManager:

Here’s an example:

class UMyGameInstance: UGameInstance{
  FTimerHandle TickHandle;
  void Tick(){ /* Do tick stuff */}
  virtual void Init() override
  {
    Super::Init();

    // Call Tick() once per second
    GetTimerManager().SetTimer(TickHandle, this, &MyGameInstance::Tick, 1, true);
  }
}

Your second question can be also be achieve by TimerManger. Either using a custom delay time or SetTimerForNextTick:

So your function “A” will look like this:

    void MyGameInstance::UpdateWidget(){
      Loading.Text = "...."
      RenderWidget()
      GetTimerManager().SetTimerForNextTick(this, &MyGameInstance::B);
    }

It works. Thanks.

An upvote or marking as accepted would be nice.

Sorry, I’m kinda new here. :slight_smile: