Object Reference in Data Table?

Hello humans,

I´m confused when would i typically use a class and when an object reference in my data table struct. It seems that I am unable to actually add data to my data table when its an object reference. Here some screenshots to elaborate:

This is how it is when i use a class:

335518-s-class.png

This works fine in most cases, however at some point I want to use functions of my skill Blueprint like “Get Description” or something. This only works with an object reference for me, however when i use an object reference in my data table struct it is like this:

335519-s-objref.png

As you can see while im able to use a “refence” in my struct, when this struct is used for the data table, im completly unable to add some skills to an data table entry despite it being an entry in the top part of the picture. It is named “RaceAbilities” at that point.

How can i have these entries in my data table and still access functions of that entry in blueprints?

Thanks

I´m confused when would i typically
use a class and when an object
reference in my data table struct

Think of a class as a template for an actor / object. You then instantiate (spawn) actors from a class based on that template and have them persist in the world until they’re destroyed. Each instantiated actor has its own data the class defined, this data can be modified.

You will almost always want a class (or a soft class) in the DT. Having an object reference in a data table makes little sense. You’d be storing just a reference to an object that has yet to be instantiated, it does not exist, its functions cannot be called.

And even after you’ve spawned an actor, you cannot store it in the DT since they’re static; a Data Table is not a data base (sadly), it is a read-only structure one fetches basic data types data from. Default values.


How can i have these entries in my
data table and still access functions
of that entry in blueprints?

Store an array of classes in the DT. When the game starts, spawn skills based on those classes and add them to an array of actor references in the player blueprint. You can now call their functions.


This only works with an object
reference for me

You can pull data out of a class using Get Class Defaults nods - this will be the original, unmodified default data. So grabbing a descriptive text would be OK this way since this text is unlikely to change. And you can even do it without spawning an actor.

Perhaps the player is browsing a shop to buy new skills; there may be no need to spawn a skill actor until the player has actually bought it. In this case reading class defaults is better than spawning an actor.

1 Like

Alright thank you for sorting some things out for me. I kinda knew that the class itself functions like a template, I was confused however because most of my skills would be passive and it made little sense to me to spawn an actor for an effect that has zero visuals and functions like a passive.

But apparently that is what i gotta do

But apparently that is what i gotta do

Consider looking into Actor Components then. Think of them as reusable chunks of script / additional functionality that can be added to actors.

If I were to design a system where abilities can be granted / taken away from actors, I’d roll with that. They are versatile but do come with limitations, too.

Short, yet great explanation:

Docs:

Here’s an example of a trap blueprint that uses an Actor Component:

Not precisely what you’re after but demonstrates the versatility and utility.