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"

Call a function from another Class(No Blueprint)

Hello Unreal Community, I'm new to C++ programming any advice or examples of my question would be very much appreciated. I have 2 classes, Class A extend GameMode and Class B extend BlurprintFunctionLibrary both created in C++. I've created a function in Class B and in trying to call that function from Class A; Is this possible?

Thanks for your help in advanced.

Product Version: UE 4.8
more ▼

asked Jun 25 '15 at 04:40 AM in C++ Programming

avatar image

15 4 4 7

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

1 answer: sort voted first
more ▼

answered Jun 25 '15 at 04:48 AM

avatar image

447 35 20 53

avatar image x1time_HAVOC Jun 25 '15 at 10:28 PM

Hey thanks for the reply but I forgot to mention that the classes were both created in c++ and not blueprint..So maybe if you can also show me an example with the c++ class that would be great...:) :D

avatar image spazchicken Jun 26 '15 at 07:18 AM

yeah, the first part of it is just C++ the blueprint part is just attaching a blueprint to the C++ class, it's not needed though.

so basically you have AClass1 and Aclass2

In AClass1 header, you put the AClass2.h header include so that way AClass1 can find/read AClass2

After that, in the header of AClass1 you would put:

 AClass2  *CurrentClass2;

in the AClass1 header you put:

 CurrentClass2 = ObjectInitializer.CreateDefaultSubobject<AClass2>(this, TEXT("Class2"));

Hope that helps!

avatar image staticvoidlol Jun 26 '15 at 11:36 AM

Just an extra note here - if you're using a pointer to an Unreal class (as most of your code would probably be) you must also decorate the pointer declaration with UPROPERTY(), e.g.

 AClass2* CurrentClass2;

Otherwise you will run into trouble with the Garbage Collection - it will destroy these objects unless you've marked them as properties.

avatar image kuo Jul 14 '15 at 04:00 PM


I am using 4.8, ObjectInitializer is undefined when I am trying to use it. Can anybody explain why?

avatar image kuo Jul 14 '15 at 04:01 PM


I am using 4.8, ObjectInitializer is undefined when I am trying to use it. Can anybody explain why?

avatar image Whytif Jun 19 '16 at 10:22 PM

Sorry, I've been looking through all of the posts and yet i still can't find the command used to call a function from other classes, you say how to set it up, but not the actual command used to call the function

avatar image x1time_HAVOC Jun 27 '15 at 12:53 AM

Thanks you guys for your quick response...But i have one more question. So the function in AClass 1 is called AClass1_Function. after I add

include AClass2.h

UPROPERTY() AClass2* CurrentClass2;

CurrentClass2 = ObjectInitializer.CreateDefaultSubobject(this, TEXT("Class2"));

All the Above is added in the Header file of AClass1. Where Exactly am i Calling the AClass_Function??

avatar image eXi Jun 27 '15 at 08:17 AM

If you want to call the function from Class 1 in Class 2, you need to do it the other way round.

You want to include the header file of the Class 1 in Class 2 and create a SubObject there. Otherwise you can only call functions of Class 2 in Class 1.

(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