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"

Game modes not being loaded from UObjectLibrary

So I decided to load maps (or levels) and game modes directly from assets folder.
I had no problems with levels, they are perfectly being loaded while PIE and grabbed by level controller (my magic automatic class for server).
But game modes ain't found by UObjectLibrary. Literally. I double checked everything.


So, declarations (somewhere in .h):

 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Level Controller")
 TArray<FString> gameModesPaths;
 UPROPERTY()
 class UObjectLibrary * gameModesLibrary;

Definitions:

 // ... Constructor
 gameModesPaths.Add("/Game/Content/GameplayClasses/GameModes");
 // ... BeginPlay
 gameModesLibrary = UObjectLibrary::CreateLibrary(ARayGameModeBase::StaticClass(), true, GIsEditor);
     if (gameModesLibrary->LoadAssetDataFromPaths(gameModesPaths) == 0)
         if (GEngine)
             GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "No assets derived from ARayGameModeBase found");
     if (gameModesLibrary->LoadAssetsFromAssetData() == 0)
         if (GEngine)
             GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "No assets derived from ARayGameModeBase loaded");

For those who lost in this mess: first I declared paths where to search for classes (objects) derived from ARayGameModeBase; then called CreateLibrary with support for Blueprint classes (there are some blueprint classes derived from this C++ one); finally I attempted to check if number of found assets returned by LoadAssetDataFromPaths isn't equal 0.
LoadAssetsFromAssetData returns 0 no matter what, means it found nothing.
Absolutely the same algorithm is used to load maps. Maps begin loaded just fine, I can travel between them using their asset names.
I checked everything:
Paths - OK;
Base class and game modes in folder have this class as parent - OK;
Truly scientific "let's make this like that and check if it works" in many variations - OK;

What am'I doing wrong? Even game modes should be spawned classes in content, ain't they?

Product Version: UE 4.16
Tags:
more ▼

asked Jul 09 '17 at 06:25 PM in C++ Programming

avatar image

HungryDoodles
490 28 19 40

avatar image BigBen1992 Jul 14 '17 at 10:21 AM

I got the same problem as yours.

     UObject* LoadObj = LoadObject<UObject>(NULL, TEXT("/Game/texture/hx1.hx1"));
     if (LoadObj != nullptr)
     {
         GLog->Log("  LoadObj->GetFName() "+LoadObj->GetFName().ToString());
         GLog->Log("  LoadObj->GetPathName() " + LoadObj->GetPathName());
         GLog->Log("  LoadObj->GetFullName() " + LoadObj->GetFullName());
         GLog->Log("LoadObjectsFromArry() LoadObj is loaded!");
     }
 
 
     int objsNum = objLibrary->LoadAssetDataFromPath(TEXT("/Game/texture/"));
     int objsNum2 = objLibrary->LoadAssetDataFromPath(TEXT("/Game/texture/hx1.hx1"));
     int objsNum3 = objLibrary->LoadAssetDataFromPath(TEXT("Texture2D /Game/texture/hx1.hx1"));
 
 
     GLog->Log(FString::FromInt(objsNum));
     GLog->Log(FString::FromInt(objsNum2));
     GLog->Log(FString::FromInt(objsNum3));




And the log is [2017.07.14-10.19.18:660][246] LoadObj->GetFName() hx1 [2017.07.14-10.19.18:660][246] LoadObj->GetPathName() /Game/texture/hx1.hx1 [2017.07.14-10.19.18:660][246] LoadObj->GetFullName() Texture2D /Game/texture/hx1.hx1 [2017.07.14-10.19.18:660][246]LoadObjectsFromArry() LoadObj is loaded!

[2017.07.14-10.19.18:671][246]0 [2017.07.14-10.19.18:671][246]0 [2017.07.14-10.19.18:671][246]0 [2017.07.14-10.19.18:671][246]No Objs!LoadObjectsFromArry failed!

LoadAssetDataFromPath always failed but LoadObject(NULL, TEXT("/Game/texture/hx1.hx1")) is OK

avatar image BigBen1992 Jul 14 '17 at 10:22 AM
 [2017.07.14-10.19.18:660][246]  LoadObj->GetFName() hx1
 [2017.07.14-10.19.18:660][246]  LoadObj->GetPathName() /Game/texture/hx1.hx1
 [2017.07.14-10.19.18:660][246]  LoadObj->GetFullName() Texture2D /Game/texture/hx1.hx1
 [2017.07.14-10.19.18:660][246]LoadObjectsFromArry() LoadObj is loaded!
 [2017.07.14-10.19.18:671][246]0
 [2017.07.14-10.19.18:671][246]0
 [2017.07.14-10.19.18:671][246]0
 [2017.07.14-10.19.18:671][246]No Objs!LoadObjectsFromArry failed!
(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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