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"

Getting an AActor like version of my blueprint to C++

So I am working on a class in c++ which should be spawning my enemies in the map on specified spawnpoint, but they only spawn whitin a certain range of the player and spawnpoints closer to the player spawn more enemies. I have a prototpe version in Blueprints, but I need to optimize it and upgrade it in C++. However this is the first time for me of programming C++ with Unreal Engine (I have programmed a bit in other langauges such as html, php, javascript, python, C++ and C++ whith a different compiler for the Arduino). My main problem is that my player is a blueprint character which inherits from another blueprint , so reparenting isn't really an option since I will have to rewrite multiple blueprints. So to tackle this problem I want to be able to get the class of my blueprint so I can use get all actors of class and for each on it (in the C++ way of course). So if I could just make it like where I have AMyClass that would be perfect, but I have no idea how to achieve this, or if it is even possible.

I have looked on the internet for a few hours now but nothing realy helped me.

Any help would be greatly appreciated.

Thanks in advance,

-Erik

Product Version: UE 4.12
Tags:
more ▼

asked Aug 05 '16 at 08:17 PM in C++ Programming

avatar image

erik321123
393 17 14 31

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

There is an undocumented function StaticLoadClass, it can get UClass from your .uasset. Here's a similar question.

more ▼

answered Aug 06 '16 at 09:54 AM

avatar image

AlekseyIlin
299 15 18 28

avatar image erik321123 Aug 06 '16 at 11:44 AM

The following lines all compile but none succeed to load the class:

 UClass* PlayerBP = StaticLoadClass(UBlueprint::StaticClass(), NULL, TEXT("/Game/FirstPersonBP/Blueprints/FirstPersonCharacter.FirstPersonCharacter"), NULL, LOAD_None, NULL);
 
 UClass* PlayerBP = StaticLoadClass(UClass::StaticClass(), NULL, TEXT("/Game/FirstPersonBP/Blueprints/FirstPersonCharacter.FirstPersonCharacter"), NULL, LOAD_None, NULL);
 
 UClass* PlayerBP = StaticLoadClass(UBlueprint::StaticClass(), NULL, TEXT("Blueprint'/Game/FirstPersonBP/Blueprints/FirstPersonCharacter.FirstPersonCharacter'"), NULL, LOAD_None, NULL);
 
 UClass* PlayerBP = StaticLoadClass(UClass::StaticClass(), NULL, TEXT("Blueprint'/Game/FirstPersonBP/Blueprints/FirstPersonCharacter.FirstPersonCharacter'"), NULL, LOAD_None, NULL);
 
 

Am I doing something wrong?

avatar image AlekseyIlin Aug 06 '16 at 12:10 PM

Add postfix "_C" to the filepath, it should look like this:

 TEXT("/Game/FirstPersonBP/Blueprints/FirstPersonCharacter.FirstPersonCharacter_C")

Unfortunately the first argument is misinterpreted in the question I linked, it has to be the base class of a class you are trying to get, not of UClass. If you look at this method's source code, you'll see this check:

 if( Class && !Class->IsChildOf(BaseClass) )

All in all, this example will work, I checked:

 UClass* Clazz = StaticLoadClass(UObject::StaticClass(), NULL, TEXT("/Game/YourBPClass.YourBPClass_C"), NULL, LOAD_None, NULL);
avatar image erik321123 Aug 06 '16 at 12:24 PM

Someone give this man an oscar XD thank you so much!

(comments are locked)
10|2000 characters needed characters left
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