UObject C++ class as BP variable - No default instance

Hello there :slight_smile:

I’m trying to make a C++ directly derived from UObject and store it in a blueprint variable.

Begining of the class .h :

The problem is that when it comes to blueprints, I can have a variable, I can call methods and it compiles well, but I canno’t set any default instance here :

And when the game is running, it causes errors :

I searched a lot on the internet and this forum, but I couldn’t find anything that worked. As a disclaimer, I already tested these :

  • BlueprintType and Blueprintable are in my UCLASS as you can see
  • If I create a blueprint class of my C++ class, it just doesn’t appear in the default value choice
  • I tried constructors with no arguments, with FObjectInitializer and without any constructor : all the same !
  • I tried to construct object directly from BP with Construct Object From Class node : same error.

Moreover : I don’t want to set my UObject an AActor. My object (a neural network in this case) doesn’t have to be spawned in the world : only held into a variable field in another actor’s blueprint.

I would be really glad if you could help me with that issue :slight_smile: Thanks !

You didn’t show declaration of NeuralNetwork uproperty.
Btw, try to change it to TSubclassOf<USNN_Network> NeuralNetwork;

Hello,

I don’t really understand what you mean by NeuralNetwork uproperty. The USNN_NeuralNetwork class has to be used from blueprint actors (like an enemy blueprint for example) as a variable field. Its use isn’t coded in C++ but aimed to be possible directly from blueprints. By the way, is there a way to do what you suggests from Blueprints ? (using TSubclassOf<…>)

(PS : I’m French, if my english isn’t understandable, let me know !)

Just to add the variable “declaration” in BP :

If you want to assign a blueprint to this field, you have to either create a factory (complex) for generated blueprint assets of the class or use TSubClassOf<> to pick a blueprint asset child of the C++ class.

  1. UCLASS(EditInlineNew, BlueprintType) or UCLASS(EditInline , BlueprintType) (array)

Question for Epic or Community on EditInlineNew - C++ Gameplay Programming - Unreal Engine Forums

That’s interesting; I’ve never found a use for that; will try it myself when I have the chance!

You can set a class reference when choosing variable type in BP (Same as using TSubClassOf<>)

ClassReference.png