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"

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

  2. Open SINGLE Blueprint, add variable TEST, type - SINGLE2 reference

  3. Create Set for TEST variable

  4. Click browse alt text

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 :)

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

Product Version: UE 4.10
Tags:
1.png (6.2 kB)
2.png (94.0 kB)
more ▼

asked Dec 25 '15 at 05:39 PM in Blueprint Scripting

avatar image

zulman
185 4 14 21

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Dec 25 '15 at 07:01 PM

avatar image

TTaM
1.7k 79 28 81

avatar image zulman Dec 25 '15 at 07:48 PM

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

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.

alt text

3.png (35.3 kB)
4.png (109.6 kB)
avatar image zulman Dec 25 '15 at 08:23 PM

Looking for details? -> Final extremely detailed explanation by TTaM is below :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 :)

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

I made it your way just classes are named "TestClass" and "TestClass2", hope it help. :)

more ▼

answered Dec 25 '15 at 07:14 PM

avatar image

TawreCZE
29 3 6 11

avatar image TTaM Dec 25 '15 at 07:21 PM

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.

avatar image zulman Dec 25 '15 at 07:52 PM

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

alt text

4.png (109.6 kB)
avatar image TTaM Dec 25 '15 at 07:56 PM

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.

avatar image zulman Dec 25 '15 at 08:01 PM

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?

avatar image zulman Dec 25 '15 at 08:20 PM

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!

avatar image TTaM Dec 25 '15 at 08:21 PM

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

Also, what happened to my reply? It's disappeared...

avatar image zulman Dec 25 '15 at 08:24 PM

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

avatar image TTaM Dec 25 '15 at 08:29 PM

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.

(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