UObject as Blueprint variable with details panel

You should use EditInline on UProperty

I want to create a custom class in C++. This class should have Properties / Functions which is different for every instance.
In a Blueprint I want to create a variable of this class. This is working, I can work with Properties / Functions aso.
But I will use this type very often, I don’t want to call “Construct My Object”, setting the variables by hand aso. In pure C++/Java I would use a Constructor.
Sure I could create a Blueprint Library with a factory for this, but this is a workaround in my opinion.
Here is an example class:

271297-defaultclass.png

The details look like this:

271300-details1.png

And should look like this:

271311-details2.png

As UClass specifier I tried variations of Blueprintable,BlueprintType,EditInlineNew,DefaultToInstanced. I think BlueprintType,EditInlineNew is needed.
As UProperty specifier I tried variations of Blueprint…,Edit…,NoClear,SimpleDisplay,Visible…. Because I like variables which are only set in constructor, in Blueprint I would tick “Instance Editable”,“Blueprint Read Only”, “Expose on Spawn”, "Private"I think this is correct: BlueprintReadOnly,EditInstanceOnly

None of the attempts worked, what do I need for it?

Iam new to C++ / UE4 so maybe I missed some keywords, feel free to point me to them.

Links:

  • [Class Specifiers][4]

  • [Property Specifiers][5]

Thank you for the quick reply.
EditInline is deprecated in 4.21.2 so I can’t compile with it.
But EditInline is part of Instanced, so I tried this. Instanced is only applicable on UObject elements and FString / bool aren’t. I even tried to use DefaultToInstanced on UClass which should set Instanced on all possible UProperty.

It looks like, that I need to provide a default instance for “MyObject”, but I don’t know how to do this. I inserted basic Constructors (Empty + Object Init and super call. Which doesn’t helped.

UMyObject::UMyObject() : Super() {
}

UMyObject::UMyObject(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) {
}

No it is property editor which should provide default object in that case. You might try to initiate the object with CreateDefaultSubobject same as component, you might also try using EditAnywhere.

UCLASS(BlueprintType, EditInlineNew)
and
UPROPERTY(EditAnywhere, BlueprintReadWrite))
was my last try

Its always “none”, even tried with different engine versions. But I have to admit, that Iam not completely sure if the “hot reloading” always worked as I expected, which could mess up specific tests, I will try it with compile/close project/reopen project.

The add Instanced to URPOPERTY(). If this wont wok you indeed need to consider CreateDefaultSubobject.

With object alone you can only pick objects that are assets.

Ok I have no clue what to do, I tried to override every suboject related function from: UObject | Unreal Engine Documentation
I tried it to log which function is called or not called, so I know if I have to override or call it.

Struggled with templates but got it to work in plain c++, doing this in ue4 c++ I get a bunch of errors I can’t resolve. Can you please give me a hint what I have do to next?

What are you trying to do now, why you looking on APIs? CreateDefaultSubobject should create object on creation, you need to do it in constructor, same as component. But im not 100% sure this other classes then components.

There no such thing as “ue4 c++” you working with normal C++, templates are supported, but UHT won’t like template on UObject as reflection system does not support templates at all.

So moving one step back, you want to create preset parameters for object to be made for a object that you can set in property panel? Maybe consider making those parameters contained in a struct and pass it on spawn, whenever you try to do it.

Sure you probably will need “factory” for it but it not big deal, not to mention it’s common practice in UE4. Also you don’t need to make “Blueprint Library” all it takes is static function on any class, “Blueprint Library” classes are either for static functions that don’t fit to any other class or to control types that blueprint can’t directly call (non-UObject or struct functions)

I’m running in the same issue with a custom C++ class inherited from UObject: if I add it as a UPROPERTY to a custom C++ class inheriting from UActor, then it shows up in the property editor as expected (your second screenshot), but if I add it as a variable in a custom Blueprint class, then it shows up as in the second screenshot (like asking to pick an asset). I suspect it’s a bug in the UE4 editor. Here my C++ code:

UCLASS(Blueprintable, DefaultToInstanced, collapsecategories, hidecategories = Object, editinlinenew, abstract)
class XXX_API UBaseFoo : public UObject {}

UCLASS()
class XXX_API UChildFoo : public UBaseFoo {}

// ... in the custom AActor
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UBaseFoo* YourChangeableObject;

Yes I want to create a preset for an object, but before this I need a default instance in property panel. I tried the CreateDefaultSubobject and needed a little bit, because if its everytime fired in constructor the project will crash on editor startup. If its an Actor I would add the returning subobject to scene / root but the UObject doesn’t provide anything like this, thats why I looked into the api. But looking in the api is most of the time my second try.

Right now I using a static function which is “the factory” but this is what I want to overcome, the explicit calling of this factory by hand over and over again. For myself, if I don’t find any sort of code for this I no longer can afford time for this specific problem.

Thanks for your help, learned a lot.

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

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!

1 Like

Thanks for your answer @Ethan_Sherr, it was just what I was looking for!

1 Like

This is great! I wish I knew about this a thousand years ago. Inline editable instanced objects is a game changer. Dark my dreams have been of late managing parameter combination named instances of objects through TSubClass. Too bad Instanced doesn’t work with TSoftObjectPtr, but it’s still cool.

Hi Ethan, I’m still not getting my SomeParams object to be exposed in the details panel of my TestActor. The only difference is that my TestActor is a blueprint actor rather than c++, so I don’t have my USomeParams property specifier set to instanced like you do. Do you know of a way to set that property specifier in blueprint?

1 Like

I am having the same problem as @SeanldMcDonld.
I cannot find a way for my Blueprint actor to allow me to set initial values for my UObject variable via the Details view.