How do I store non-actor objects with functions?

I am a newbie with Unreal, and I got a project I’m trying to prototype, to see if Unreal is the right engine to use.

So, here is the criteria for what I am trying to make.

The setting is a spaceship with a generational crew.
The spaceship consist of 3 types of objects:

  • Modules (rooms)
  • Crew
  • Jobs

The modules will be displayed in a way similar to the base layout in the game X-COM (2012).


Each module can be rebuilt into a different type of module (habitat, workshop, hydroponics, etc.)
Module objects contain child objects that define their use. For this prototype, that is just limited to different types of jobs.
It should be possible for a module to have more than one job.

Crewmen are individual objects with names and age.

Each crewman may be assigned to one or more of any job object.
If a module is changed, the job is replaced or removed, and thus the crewman lose the job assignment.

Jobs may function differently from each other, but are all called in the same way as a game progress though a game-turn.
A farming job may add food to storage, a workshop job may add a piece of equipment.
(In this prototype, they will just print to log each game-turn)

I have already prototyped this in Java, but I wish to recreate this in UE4 Blueprints.
I am, however, unsure how to set this up, as the Blueprints system does not seem as straight forward as advertised.

I learned about the GameMode Blueprint, and how I may use it as the main structure to hold the data and progress the game turns.
I found the Enum and Struct types, and found some limited use of them to store the type and location of each module/room.
I suppose I could also make a struct for crewmen, and put those in an array.
But I can’t define any functions for structs and enums, so that won’t do for jobs.
And from what I can see of the Blueprint classes, all other alternatives are for static values or visual objects.

I am pretty sure I am misunderstanding or missing something, but hey, that’s why I am asking for help.

Bring My Post Up!

What do you mean by ‘functions for structs and enums’?

For sure, you can make functions, and the can take data structures as arguments.

I’m coming from Java, my c++ is rusty at best, and I have never touched blueprints before, so I might not think in the right way on how to code for this.
My existing code in java, which I hope to part over, use some abstract base classes and then a number of implementations for the different types of object.

A class for a workshop and a class for a hydroponics both inherits from the same abstract class, and I call the same function on them both, but the way this function operates are different.

I have tried to create a class in blueprints, inheriting from the Object base class. But when I go into my GameMode Blueprint constructionscript, I find no Create option for the new class.
I do find it for structs.

I just found a tutorial video mentioning “object reference” and “class reference” by declaring a local or class variable.
I think this might be what I was missing.

Take a look at Actor Component and BluePrint Interface

You can’t create a class inside a BP, you create it outside, in the content browser. There, it can inherit from other classes etc… Inside the BP, that’s where you define the behaviour of a given class.

That raises a question.
Should I use an actor component or an object (lowest level base class) for back-end data?
While I do intend to have visible game objects (actors, gui?) that represent this data, I wish for the data to be accessible at any scene / level, whatever the term is.

The plan for this first stage prototype involves just one scene, one where I configure the ship’s module and crew assignments. But later I plan on introdusing star-system navigation, extra-stellar navigation and, eventually, ship combat.
But hey, one step at a time.

Anyways, I think I understand how to use Blueprint Interface. I will update this thread if I struggle with it. Thanks the tip.

I would go for Actor. It doesn’t neccessarily mean the object will have visible components…

I may be totally off as to what you want here. But the general idea I got was you wanted to have a module (3D asset) …say a Workshop . That module would have functionality to spawn equipment based on interaction.

If this is correct then my approach would be to first design the module… all the static meshes etc on a level, then convert them to a Prefab. This creates an Actor Blueprint class (Workshop_Module).

Next I’d create and Actor Component named Workshop_Component, then create a BP Interface and add it to the Component.
Then add that Workshop_Component to the WorkShop_Prefab.

Open the component, add all the variables and functionality to it. Then use an interface to interact with said functionality.

Sounds complicated, but it really isn’t.

The point of the Actor Component is to house all the vars, logic etc for the module. For other modules you can simply duplicate the actor component class, modify and add to their respective prefab class.

You could take this a step further and have a “Parent” ModuleComponent with all the universal assets/vars/functionality, then create a child class for specifics (habitat, workshop, farming etc).

PM me if you want a vid demo or more info.

Half true. The 3D model is not in the picture yet, just the data.
At this first stage, I intend to just use UI elements to represent the objects, so to simplify the project. Any 3D assets would be just for looks and aesthetics, somehow referencing the data.
Equipment, food products, water-storage etc type of object might never have any 3D assets of their own, though I might make them visible as part of the cargo module.
In any case, I will deal with 3D assets later.
Everything will be represented with 2D UI for now. That means image files, once I figure that out.

I suppose it wouldn’t hurt to make the objects compatible with Actor objects from the start.
What holds me back, is ignorance on how Unreal handles objects.

I might take you up on that offer. I definitely wish to understand Unreal better.
For now though, let me show you the structure I sat up yesterday.




I’m sure you all can point out a dozen things I do wrong here, so please do.
I’m gonna continue tinkering with implementing some crew data and mechanics to the ship while waiting for your reply.

Well, that’s yet another brick wall hit.

I need a way for the crewman objects and the job objects to communicate.
For that, they needed to access each other, and their only common link is the Spaceship GameMode class.

The base Object class can’t access GameMode or GameState for some reason.
And it seems Blueprint don’t have static variables and functions, so I can’t make a singleton pattern either.
So, if I am to continue my current structure, I got the following options:
I could save a reference to the Spaceship class for every object it holds, making it less and less meaningful for it to be inheriting GameMode.
I could call every function from the Spaceship class, passing self-reference to child objects when needed.
I could change the objects to inherit from Actor Components instead, not knowing what consequences might come from that.

Maybe my approach is wrong.
Well, I’m gonna pause development on Unreal until I hear from you folks.

Gamemode resides on the server only. Clients do not get a copy.

Logic Flow:

  • Client interacts with module/component
  • Module/Component sends request/RPC to server (Game mode)
  • Game mode facilitates action on the server (grow food) … .can i grow food: True → do so.
  • Replicates return to module (RPC -> multicast)
  • Module produces food (client local).

What is client and server in the context of a single player game?

There’s always a server. Even in SP. The game mode would reside in it…isolated from the client. The only interaction between the two is through events.

When something is generated would be handled by the game mode. Say food, equipment etc.
If a player can harvest said items would be mitigated by the game mode. Do they have room in inventory etc.

Seems like your last question can be boiled down to “how do you communicate between blueprints?”

There are several ways.

First and easiest, the level BP. It has access to any actor in the level, so you could easily check proximity of one actor to another within it - perhaps by a custom overlap.

Second and perhaps the best. (The answer you already got)
Blueprint Interfaces.
you simply create an interface with a function named aptly for what you need to do, and implement the function within the actor giving it the custom code to run in case this interface is called.
This essentially enables you to dig out a reference to whatver you need to interact with, and call a function. If it exists stuff will happen. If it does not it won’t.

It depends on what and how you are generating really. Your initial question/idea isn’t too clear.

Each actor/object has it’s own set of variables.
Every crew member on a ship would be it’s own actor/object implementing it’s own AI.
The ship itself wouldn’t necessarily control anything about those actors, except perhaps limit how many it can contain or similar.
The level BP instead contains all the information about anything in the level. This would come in handy to create scripted functionality for a character to move from A to B for instance if you are being lazy about implementation and ai

Thanks for the help so far.
Much of the confusion comes from how little I know of how Unreal works.
And some comes from how bad I am at explaining things.

So, to backtrack.
What I really want, is a complex structure of data that persists even when switching levels.
From what I so far understand of Actors and ActorComponents, those are destroyed when switching levels.
This is why I am hesitant to use ActorComponents.

Have have used the Blueprint base class Object for my modules, crew and jobs.
However, as I have learned though my trial and error, the base Object class lacks some vital access.
I can’t access the game mode, game instance, game state or the like from it.
But I can when using am ActorComponent class.
I have tried to find out why, but so far no luck.

So, I am once again rethinking my structure, and come up with an idea.
Since I am not entirely confident, I would want some input on whatever this is a good solution.

I only just recently learned of the **GameInstance **and **FunctionLibrary **blueprints.
Unless I misunderstand, **GameInstance **remains persistent all the time, no matter what level I were to load. Exactly what I want.
So I can use an **GameInstance **as a database of sorts.
The data can be stored as Structs, instead of blueprints, and stored in arrays, or maybe maps.
The different types of **modules **or **jobs **can be set with an **Enum **value.
To better allow the **struct **objects reference each other, I could assign each one their own **unique ID **variable.
Then I can use a FunctionLibrary to fetch and set data stored in the GameInstance.

Then in a **GameMode **Blueprint, I can call the functions from the **FunctionLibrary **to manipulate the state of the game.
The **different **behaviors of jobs, modules and crewmen can be implemented with a **branch **on the **Enum **values.

Funny side-note: Seems a FunctionLibrary is the exact inverse of a Struct. So it would be fitting to use them together like this.

@KvaGram

Game instance

Get Game Instance

Video explaining it: HTF do I? Save Variables between Maps ( UE4 ) - YouTube

Save Game Object

Video Explaining it: HTF do I? Use the SaveGame Object in Unreal Engine 4 - YouTube