Trying to get variables from data only UObject failed


For my plugin i have an separate UObject that hold data and i’m trying to access it via c++.
I made a child of it with blueprint to fill in the data.

I’m trying to get the variables from the data asset for my building constructor actor. By having the “building kit” data in separate assets it will be easier for the user to use the tool.

so for the code i’m using

When my actor is being spawned in the world via my plugin a reference to the UObject is made with this code;
This is an asset in the content browser, not an asset in the world.

   UObject* BuildingKitDataStruc = LoadObject<UObject>(NULL, TEXT("/Game/Graphics/BK_PlaceHolder.BK_PlaceHolder"), NULL, LOAD_None, NULL);

With a getter my spawned object will receive the reference.

in the plugin:

AMyBuildingConstructor* MyConstructor = Cast<AMyBuildingConstructor>(Actor);


And the function in the actor:

void AMyBuildingConstructor::GetBuildingKit(UObject* InputObject) { BuildingKit = InputObject; }

The reference seems to be linked when spawned.

With this part of code i’m trying to fetch the TileSize Data from my data only UObject.

UMyBuildingKit* MyObjectData = (UMyBuildingKit*)BuildingKit;
if (MyObjectData)
	UE_LOG(LogTemp, Warning, TEXT("TileSize building kit variable is: %d"), MyObjectData->TileSizeInput);

with this way i’m getting weird values, but no crash.

LogTemp:Warning: TileSize building kit
variable is: -1250945536

With normal casting I’m always getting a nullptr; so i’m getting nothing.

an other method i tried was one of the awnser i found on the hub;

	UMyBuildingKit* ClassDefaultObject = MyBuildingKitDataStruc->GetClass()->GetDefaultObject<UMyBuildingKit>();

this sadly enough didn’t work.

I have been looking around on the answer hub and tried other things to without much results;
I hope i just made a silly mistake that can be resolved easily :slight_smile:

Thanks in advance and i hope somebody can help me with this!




the code in the data holder object

class BUILDINGCONSTRUCTOR_API UMyBuildingKit : public UObject

	/* Primitive data*/
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 TileSizeInput;

	/* Mesh Data*/
	UPROPERTY(EditAnywhere, Category = "Meshes|1 Tile")
		TArray<UStaticMesh*> BK_Floor1t;

	UPROPERTY(EditAnywhere, Category = "Meshes|1 Tile")
		TArray<UStaticMesh*> BK_Wall1t;

	UPROPERTY(EditAnywhere, Category = "Meshes|1 Tile")
		TArray<UStaticMesh*> BK_UWall1t;

	UPROPERTY(EditAnywhere, Category = "Meshes|1 Tile")
		TArray<UStaticMesh*> BK_Corner1t;

	UPROPERTY(EditAnywhere, Category = "Meshes|1 Tile")
		TArray<UStaticMesh*> BK_UCorner1t;

	UPROPERTY(EditAnywhere, Category = "Meshes|2 Tile")
		TArray<UStaticMesh*> BK_Wall2t;


After doing research i stumbled on this method; GetDefaultObject to get the values.


sadly enough this end up crashing.

Assertion failed: Ret->IsA(T::StaticClass())