x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UObject as Blueprint variable with details panel

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: alt text

The details look like this: alt text

And should look like this:

alt text

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:

Product Version: UE 4.21
Tags:
defaultclass.png (8.3 kB)
details1.png (47.8 kB)
details2.png (44.4 kB)
more ▼

asked Mar 13 '19 at 10:15 PM in C++ Programming

avatar image

terzut
26 2 2

avatar image Kafumanto Mar 22 '19 at 11:49 AM

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;
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You should use EditInline on UProperty

more ▼

answered Mar 13 '19 at 10:24 PM

avatar image

Shadowriver
36.6k 932 169 1111

avatar image terzut Mar 14 '19 at 12:41 PM

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) {
 }
avatar image Shadowriver Mar 14 '19 at 06:27 PM

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.

avatar image terzut Mar 14 '19 at 06:33 PM

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.

avatar image Shadowriver Mar 14 '19 at 06:55 PM

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.

avatar image terzut Mar 16 '19 at 06:55 PM

Ok I have no clue what to do, I tried to override every suboject related function from: https://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UObject/index.html 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?

avatar image Shadowriver Mar 17 '19 at 03:15 AM

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)

avatar image terzut Mar 24 '19 at 06:09 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question