Download

Setting default value of UClass(BlueprintType)

Hiya, I’m trying to add a generic matrix type to blueprint by creating a UCLASS with the blueprinttypw specifier and providing properties like rows/columns along with some functions to operate on it.

I can create the reference variable in a blueprint, and make it instance editable, but it still needs to be constructed either as an hard asset or created in the blueprint (with a factory BP function i added to a BP function library). Interestingly, calling construct object from class gave back a null object. Create the object from a factory function was the only way to get it to work.

I’ve seen lots of posts in the answer hub about adding DefaultToInstanced and EditInlineNew to the class specifier but its not doing what I expect.

Is it even possible to be able to set default properties on a variable of this type on uclasses without constructed them?

I did try just wrapping it up in a USTRUCT which kinds of works as it allows me to set the properties (at this point, just two int for rows and columns). But I can’t do any post property initialization on the USTRUCT.

This post seems to suggest adding the extra class specifiers should do what the person and myself want, but so far I can’t seem to get it to work.
https://answers.unrealengine.com/questions/790030/postinitproperties-funcitonality-for-a-ustruct.html

I appreciate any help on this matter :slight_smile:

#pragma once

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


UCLASS(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;
};

I don’t understand the question to be honest. Set default value of what? The matrix variable?

No , when you create a variable of type UEigenMatrix in a Blueprint. I want to be able to set rows and columns properties in the properties editor of the UEigenMatrix variable.

That also brings up another point. Is the internal member ‘Eigen::MatrixXf matrix’ going to be instanced per blueprint? I can’t make it a property (I get an error about a delegate or something).

I can do what I want with creating the UEigenMatrix variable with a factory method like I said in the first post, but would like it to already be constructed when I add a blueprint variable. I guess since its a reference, the blueprint cant automatically construct it? But from the limited description of EditInlineNew, it sounds like thats what that class specifier should do.

I also forgot to link the post I mentioned which explains the issue more clearly…

https://answers.unrealengine.com/questions/790030/postinitproperties-funcitonality-for-a-ustruct.html

thanks :slight_smile: