Several questions about childldren of UObject C++

Hi, all! I would like to know about childldren of UObject instantiating.
For example I have following base class:

class UAbility : public UObject {
	GENERATED_BODY()
public:
	UAbility();
        ...
};

If I use it as Object reference in data table struct I can not set nor default value, nor value in specific row

image

Ok, it’s a not big deal I can use TSubclassOf< UAbility> and create object from class, but in general is it possible to have reference in data tables and other editor related views? Maybe I missed something, as I understand for any UCLASS and UObject children the default object is created, why can’t I use it?

So, next. I use TSubclassOf and create object :

auto ability = NewObject<UAbility>(this, Row->AbilityClass)// NAME_None, RF_NoFlags by default;

and store to component:

class UCharacterAttributesComponent : public UActorComponent
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, SaveGame)
	TMap<FString, UAbility*> Abilities;

The issue is after save/load the map has correct amount of elements and keys of map, but all references to UAbility objects are empty.

And only if I use flag RF_Load on creation all works as expected.

auto ability = NewObject<UAbility>(this, Row->AbilityClass,  NAME_None, RF_Load);

What is a magic here? RF_Load is combined flag, but idk which part of it does the save/load job. I doubt, it’s a good idea mark each created object as RF_ClassDefaultObject which is part of RF_Load. I could blindly check all of them, but I would like to understand what’s happening…

Thx for attention )

(gameplay) Object references (blue pins in blueprint) are not valid while working in the editor.

You can use soft object pointers (c++ or orange pin) to reference an asset on the disk, or class references (UClass purple pin), which you will be able to set in your datatables and variables.
From the class reference or TSoftObjectPtr you will be able to instantiate an object when required during gameplay.

Thx for your answer, but if I understand correctly from that article Referencing Assets | Unreal Engine Documentation the only difference between hard ref and soft ref is time when object is loaded to memory. In case soft ref it’s lazy loading. And if hard ref is used all object will be loaded when data table is used even if some of them are not required at the time.

I’ve tested soft refs as well it didn’t help to solve issue


Where asd is a child of uobject

You can’t select a blueprint class from your content browser as an object or soft object reference, since it’s not really instantiated yet. A blueprint is a class, not an object of a class. Blueprints do have a default object, which is created when the editor is launched, but that is only used for internal purposes, and generally should not be referenced or modified during gameplay. So when you have an object or soft object pointer variable, you need to populate it with an actual object in the world basically.
The correct approach should be using a class reference and constructing a new object of the ability at runtime.

1 Like

Thx for answer. I’m mostly agree with you, except one thing.

UCLASS(hidecategories=Object, customconstructor, MinimalAPI, BlueprintType, config=Engine)
class UStaticMesh : public UStreamableRenderAsset, public IInterface_CollisionDataProvider, public IInterface_AssetUserData

which can be used as object reference. But it’s related only to assets such as mesh anim or texture. I’ve thought I used Actors as object reference, but after checking - no, I use class ref indeed.
Anyway, when I create new object without RF_Load flag it can not be save\loaded by FArchive So which part of this combined flag is related to actual save load proccess and why )