Property that can take a Blueprint reference or an Object reference?

I have a class that has an Object property to reference an object that is some data:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Vehicle)
UVehiclePhysicsSetup* PhysicsSetup;

I prefer using an Object property instead of TSubclassOf because it has the flexibility of being able to be assigned an editor asset (created ahead of time in editor), or a runtime asset (constructed at runtime, say from data from the online backend). However it would be nice to be able to assign a Blueprint to it as well (assign the Blueprint’s Default Object to the property). Is there anything that would allow this?

Without some extra code, no and it’s actully limitation on C++ side, object creation function only accept UClass* (TSubclassOf is UClass* template) at most you can create object on object creation with CreateDefaultSubobject in constructor, but it wont let you pick subclass of object.

But you can do something like this:

 UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = Vehicle)
 UVehiclePhysicsSetup* PhysicsSetup;

 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta=(DisplayName="Physics Setup"),Category = Vehicle)
 TSubclassOf<UVehiclePhysicsSetup> PhysicsSetupClass;

This will make 2 varables visually visible as in blueprint defaults as UClass and in level property editor as object. Now on begin play you would check if PhysicsSetupClass is not null, if it is not null, create object of that class.

Now about extra “extra code”… if UVehiclePhysicsSetup is just class holding variables, you might consider turn it in to asset type and save those as assets instaed of blueprint classes. As assets they will exist as selectable object in blueprint defaults. By default if you don’t define editor for your asset type, it will open it in property editor

There also quicker method by making UDataAsset class

Only downside of this method is you won’t have fency menu entry for your asset creation (you will need to create it via “Data Assert”) and you wont be able to control appearance of the asset in Content Browser, as well as potentially making custom editor for it