Pointer to UObject and Inheritance in BP/C++

Hi, here is my WTR story (UE4 4.10.1):

  1. Make new Blueprint class, just extending Object - SINGLE & SINGLE2

  1. Open SINGLE Blueprint, add variable TEST, type - SINGLE2 reference
  2. Create Set for TEST variable
  3. Click browse

Result - nothing to select. But as we remember in step 1 we’ve created SINGLE2 object. Same situation with any c++ approaches (via direct pointer to any SINGLE2 object) except of TSubObject, but it’s not what i’m looking for :slight_smile:

What i’m doing wrong (i want to be able to select SINGLE2 object)? Thank you :slight_smile:

Creating a variable of a given type does not create an instance of that type when it’s a pointer. It creates a pointer (int) to that type. All UObject (and its descendants) variables are pointers.

Calling it a reference is misleading. It is not a reference (&), it is a pointer.

To have an object selectable in the dropdown, it would need to be in the content browser. It is not possible to create UObjects (or any of its subclasses) in the content browser, except for specific asset classes, such as UStaticMesh or UTexture.

Yeah. That was my point. You’ve created 2 UObject classes (or blueprints.) Instances of these classes are not assets, they are just regular objects.

It’s not asset it’s class. How I understand it, assets are things you can place to the world/BP, you made a class you need to construct like other basic classes, so you need create instance of class :slight_smile:

Just tried it in editor and you need Event/Function after creation if you want it keep it on OOP way.

I made it your way just classes are named “TestClass” and “TestClass2”, hope it help. :slight_smile:

Creating a variable of a given type does not create an instance of that type when it’s a pointer.

Sure, i understand it.

Calling it a reference is misleading. It is not a reference (&), it is a pointer.
Sure, thank you. That was misleading really since Epic using reference word :slight_smile:

71914-3.png

To have an object selectable in the dropdown, it would need to be in the content browser.

May be, but it’s hard to get just because if i will make Object/Reference variable TEST2 i will be able to select my blueprints via same dropdown.

Thank you, got it. But would you be so kind to define the difference between my original case (SINGLE & SINGLE2 classes) and basic Object class - why i able to select my blueprints as Assets in dropdown for variable TEST2 (Object/Reference)? Thank you

TEST2 is of the UObject* type - this means every object which extends from UObject is a valid “reference” - You can set any asset there or any class.

UE4 creates objects for each class. Class descriptors basically. This is what you can select there; not objects of those classes, but the classes themselves.

What you want to do, I think, is select instances of your classes - this isn’t possible because instances of your classes are not assets.

Now i’m closer to understanding, thank you. Basically i want to create BP_ParamContainer, set in this some params/values and then use it in BP_Main as variable to access my values. What is the best practice for it?

Something to know before you start, for every UObject class you create, UE4 creates a “default instance” - there is where all you default values are stored. It’s called the CDO - class default object.

Now, if you want to just get “hard coded” values from something, you don’t need to create an instance of that class to do it - you can use the class default object.

So, what you do:

  • Create a base blueprint which has all your variables with default values. Let’s say you call it BP_ParamContainer.
  • Create a subclass called BP_ParamSetOne and set default values in that class - this is your “instance”, but it’s actually a separate class.
  • In BP_Main, create a TSubclassOf (or class variable (the purple ones)) variable and select type BP_ParamContainer
  • Set your class variable to BP_ParamSetOne
  • You can now use Get Class Defaults on your variable to get the values set in BP_ParamSetOne

Basically, you use blueprint subclasses like instances. I don’t know if this is best practices, but it’s very easy to set up once you’ve done it once.

Something to know before you start,
for every UObject class you create,
UE4 creates a “default instance” -
there is where all you default values
are stored. It’s called the CDO -
class default object.

Now, if you want to just get “hard
coded” values from something, you
don’t need to create an instance of
that class to do it - you can use the
class default object.

So, what you do: - Create a base
blueprint which has all your variables
with default values. Let’s say you
call it BP_ParamContainer. - Create a
subclass called BP_ParamSetOne and set
default values in that class - this is
your “instance”, but it’s actually a
separate class. - In BP_Main, create a
TSubclassOf (or class variable (the
purple ones)) and select type
BP_ParamContainer - Set your class
variable to BP_ParamSetOne - You can
now use Get Class Defaults on your
variable to get the values set in
BP_ParamSetOne

Basically, you use blueprint
subclasses like instances. I don’t
know if this is best practices, but
it’s very easy to set up once you’ve
done it once.

Thank you! So finally the only thing to complete my brain challenge for this question - am i right that there is no way to have pointer to this “default instance” of any blueprint class? Thank you so much!

In c++ you can. In BP, you can only get the default variable values.

Also, what happened to my reply? It’s disappeared…

Looking for details? → Final extremely detailed explanation by TTaM is below :slight_smile:

Can’t see it here too, only in email notification.

Reposted because the formatting was horrible:

Something to know before you start, for every UObject class you create, UE4 creates a “default instance” - there is where all you default values are stored. It’s called the CDO - class default object.

Now, if you want to just get “hard coded” values from something, you don’t need to create an instance of that class to do it - you can use the class default object.

So, what you do:

  • Create a base blueprint which has all your variables with default values. Let’s say you call it BP_ParamContainer.
  • Create a subclass called BP_ParamSetOne and set default values in that class - this is your “instance”, but it’s actually a separate class.
  • In BP_Main, create a TSubclassOf (or class variable (the purple ones)) and select type BP_ParamContainer
  • Set your class variable to BP_ParamSetOne
  • You can now use Get Class Defaults on your variable to get the values set in BP_ParamSetOne

Basically, you use blueprint subclasses like instances. I don’t know if this is best practices, but it’s very easy to set up once you’ve done it once.