PostInitProperties funcitonality for a USTRUCT

I’m trying to create a new BlueprintType with a USTRUCT. I expect to be able to do the following:

  • Make new variable in a blueprint (with my new type)
  • Set defaults for the new variable (in the blueprint)
  • The other members of the variable are initialized based on the specified defaults

Obviously I cannot use the PostInitProperties function in a struct since it is defined in UObject.

But if I change my struct to a class derived from UObject, I can’t edit default values in the BP editor:


In other words, how do I remove the need for a custom initialization function? 99.9% of the time, it will be in this exact spot:

241252-init.png


Or look at it this way:

In code alone, I’d just use parameters in the constructor to instantiate unique instances of a class/struct. How do I accomplish this with my C++ class when I am instantiating it in UE Blueprints?

I’d like to use it as a variable in Blueprints, so I don’t want to have to create child Blueprint classes of my data class every time I simply need different defaults.


Is something like this possible, a feature request, or against UE4 standards/workflow?

I dont think that possible, default are stored in CBOs Class Defaults Object and struct is stored as a part of a class/object an both defaults and serialization in to the file, when you got PostInitProperties this includes all structs in the class.

You can create custom widget for property editor for your struct, maybe you could try doing something with that and leave constrcutor to do the work on C++ side:

Doing construction nodes is also valid solution but user can still normally make structs with make node

I’m not sure I understand. Could you elaborate on the two workarounds you mentioned?
Concerning the first, I don’t think I can add access to properties through UI customization?

Use the UCLASS approach and mark it as UCLASS( Blueprintable, DefaultToInstanced, EditInlineNew ). Define your TestArray as UPROPERTY( Instanced, EditAnywhere ). Should get you all the benefits.
You may find additional information in the code-definition of those macros and on answerhub ;D though, setting to defaults and saving may be some fiddling…

1 Like

I’ve had the same issue as OP, and have been trying this, but I still see “Default Value” instead of the properties I have in the UCLASS. Here’s the code…

#pragma once

#include "CoreMinimal.h"
#include <Eigen/Dense>
#include "EigenMatrix.generated.h"


UCLASS(BlueprintType, Blueprintable, DefaultToInstanced, EditInlineNew )
class DOKIFLUIDDEVTOOLS_API UEigenMatrix : public UObject
{
	GENERATED_BODY()
public:
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite,  Category = "Player Variables")
	int32 rows = 1;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")
	int32 columns = 1;

	Eigen::MatrixXf matrix;
};

using the Meta specifiers on the UClass defenition and at the UProperty, it looks like this which is like using a Struct but with the actual Class selectable:

341416-instancedclassproperty.jpg

UCLASS( BlueprintType, Blueprintable, DefaultToInstanced, EditInlineNew )
class SPACENEBULASTARFIELDV3_API UEigenMatrix : public UObject
{
	GENERATED_BODY()

public:
	UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = "Player Variables" )
		int32 rows = 1;
	UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = "Player Variables" )
		int32 columns = 1;

	FMatrix matrix;
};

UCLASS()
class SPACENEBULASTARFIELDV3_API ATestActor : public AActor
{
	GENERATED_BODY()

public:
	UPROPERTY( Instanced, EditAnywhere, BlueprintReadWrite, Category = "Player Variables" )
		UEigenMatrix* NewVar0;
};

Thats good to see, however I’m not using my UEigenMatrix as a property in another Actor class. I’m using it directly as a blueprinttype (potentially in a blueprint utlility).

This seems to be for creating Blueprint classes only, OP wants to create a class/struct for BP variable types (like, variables in a BP, not new BPs)

Have anyone found a solution to this? I’m in the same situation, currently considering to go for a struct and correct data every time I access it, but that feels quite wrong tbh