Assign BP of ClassA to UPROPERTY of ClassB in editor

Hi everyone.
I’m trying to achieve the following. I got two classes A and B. A is a UObject and has the


UCLASS(Blueprintable, BlueprintType)

macro. B is a APlayerController and has a


UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="X") ClassA* a

I want to be able to assign a ClassA_Blueprint to that UPROPERTY in the editor, but I’m not able to do it. What am I doing wrong?

Thanks in advance.

I don’t have access to the editor and my project right now, so can’t check to be 100% sure, but I think you’ll want to change the UPROPERTY in class B to look as follows:


UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="X") TSubclassOf<ClassA> a

The reason for this is that Blueprints you create in the editor essentially are classes themselves, and not objects. With the code you previously had, you would be able to select an instance of the blueprint if you had dragged that blueprint into some level (which would only be possible if it were Placeable though).

When using TSubclassOf<ClassA>, you will also have the option to select the C++ class ‘‘ClassA’’ itself, in addition to any blueprints with ClassA as a parent. If this is undesired (for example because you use the blueprints to assign values to various properties, and the C++ class does not have correct values assigned by itself), you can use the HideDropdown specifier in the UCLASS() macro of ClassA.

One last tip: If your ClassA is purely intended to contain data and it is not necessary to ever use the full functionality of Blueprint graphs in objects of ClassA, I would recommend having ClassA extend UDataAsset instead of UObject. Then, assets are created in the editor through Miscellaneous -> Data Asset instead of through the Blueprint menu options, and then you’ll want to keep the UPROPERTY as it is now (a pointer instead of a TSubclassOf).

Thanks, I’ll check it out as soon as I can. The class will basically have a few properties and functions. It will be used to map real world coordinates to virtual world coordinates. I think it would be agood idea to keep the functions blueprint callable. Will the UDataAsset still be a better choice?

You can still have BlueprintCallable functions in a UDataAsset, and still use it as a variable in another Blueprint graph if you keep the BlueprintType specifier in the UCLASS() macro. The only difference is the asset itself will not have a Blueprint graph, so you can’t add events to the asset itself, but it can still be used in graphs of other ‘‘real’’ blueprints that DO have a graph. I suspect UDataAsset would be a better choice, it seems more ‘‘lightweight’’ to me than a full blueprint due to the absence of a a Blueprint graph and a compilation process, and I expect that if those features were not used to begin with, their absence should result in better optimization. It’s only what I expect though, don’t have hard facts to prove it and can’t be 100% sure.

I am doing this same thing in my project and it works as is, without TSubclassOf<ClassA>, in 4.6.1, both from the viewport editor, and from the blue print editor.

:confused:

But it’s not the same thing at all.

UFoo* MyFoo; // Instance of Foo object (or object deriving from Foo)
TSubclassOf<UFoo> MyFooClass; // Foo class (or class deriving from Foo)

Thank you, I got it working with the TSubclassOf<ClassA>. The pointer didn’t work.