UObject as Blueprint variable with details panel

Hello. I was running into the same issue and solved it for my use case -
just want to put it out there to update this thread incase anyone finds it.

I ran into this post about UPROPERTY flag Instanced, and UCLASS flags DefaultToInstanced, and EditInlineNew
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/24885-the-instanced-flag-for-uproperty
the user cmartel explains it very clearly and I recommend checking it out.

In short, here’s what I did in my own project.
I have c++ actor, and a c++ UObject. I want the Actor to expose this UObject in its parameters, and I want each actor to have different objects, as well as I’d like that all of the actor’s object params to be configurable in the level editor. Also, I want to extend the object params (in c++ and bp) and have those params also be exposed for this actor.

Step 1)
The actor cpp:

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "TestActor.generated.h"

class USomeParams;

UCLASS(Blueprintable)
class SPACEFORCE_API ATestActor : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	ATestActor();

	UPROPERTY(Instanced, EditAnywhere, Category = Test)
	USomeParams* SomeParams;
};

step 2, the params uobject cpp:

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "SomeParams.generated.h"

UCLASS(DefaultToInstanced, EditInlineNew, Blueprintable)
class SPACEFORCE_API USomeParams : public UObject
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere)
	FName Name;

	UPROPERTY(EditAnywhere)
	int age;
	
};

The Params has a UCLASS specifier DefaultToInstanced, because I want it to be Instanced every time its used, rather than using the same instance (unlike for example, UTexture2D). EditInlineNew I think makes the editor create a new instance of the TSubclassOf when the USomeParams is used as a UPROP, and edit it inline, I believe.

This is a BP_TestActor that inherits ATestActor. You can see I can assign & edit the SomeParams in the TestActorBP & in editor.

Also I want to make a BP_Params that inherits USomeParams. I’ll add a bool LikesPinapplePizza and ofc default it to true.

Very nice: it is also selectable and editable in the BP_TestActor’s properties. Sweet.

I hope this is helpful for anyone who ends up here!

4 Likes