Announcement

Collapse
No announcement yet.

FAssetData.GetAsset

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    FAssetData.GetAsset

    I am trying to dynamicly load blueprints:
    First I load assets in UObjectLibrary like that:
    Code:
            UObjectLibrary * lib = UObjectLibrary::CreateLibrary(base_class, true, GIsEditor);
            lib->AddToRoot();
            int32 loaded = lib->LoadBlueprintAssetDataFromPath(path);
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::FromInt(loaded) + TEXT(" objects loaded for lib - ") + name);
    -------------------------------------------------------------------------------------------------------------------------
    Then i`am trying to find asset by name, then load in by FAssetData::GetAsset, and return TSubclassOf<Ship> to spawn in blueprints;
    Code:
    lib->GetAssetDataList(Assets);
    	for (int32 i = 0; i < Assets.Num(); ++i) {
    		FAssetData& assetData = Assets[i];
    		if (assetData.AssetName.ToString() == name) {
    			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("AssetFound - ") + assetData.AssetName.ToString());
    							
    			if (!assetData.GetAsset())
    				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Get ship: Failed to load object by GetAsset - ") + assetData.AssetName.ToString());
    
    			UBlueprint * bp = Cast<UBlueprint>(assetData.GetAsset());
    			if (bp) {
    				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Get ship: bleprint cast done for asset - ") + assetData.AssetName.ToString());
    				if (bp->GeneratedClass->IsChildOf(AShip::StaticClass())) {
    					return *(bp->GeneratedClass);
    				} else {
    					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Get ship: Class isn`t cild of AShip- ") + assetData.AssetName.ToString());
    				}
    			} else {
    				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Get ship: bleprint cast FAILED for asset - ") + assetData.AssetName.ToString());
    			}
    		}
    	}
    In editor this code works perfectly, as well as in <Play->Standalone>. But when i bush Launch, and Unreal builds really "standalone" game for me, assedData.GetAsset returns NULL. I can`t undestand why it fails to load object.

    #2
    I find out that StaticLoadObject(called by GetAsset) fails to load my blueprint with the message:
    LogUObjectGlobals:Warning: Failed to find object 'Object /Game/blueprints/ships/FirstShip.FirstShip'
    I also, find out that StaticFindObjectFast returns NULL for me when i Launch the game and works fine when i bush "Play" Button.

    May be it`s a BUG?

    Comment


      #3
      I may be way off base, but I'm guessing some of these systems only exist with the editor build - look for "WITH_EDITOR_ONLY" in the headers.
      Storyteller - An immersive VR audiobook player

      Dungeon Survival - WIP First person dungeon crawler with a focus on survival and environmental gameplay ala roguelikes

      Comment


        #4
        I sorted out the problem.
        UObjectLibrary::LoadBlueprintAssetDataFromPath(path) - loads info about blueprint assets by path. In editor mode i can get them, and then get GeneratedClass of them. When game is cooked there is "no blueprints" there is only GeneratedClass. So i can load GeneratedClass directly by adding "_C" to object path.

        Comment


          #5
          Originally posted by MadScorp View Post
          I sorted out the problem.
          UObjectLibrary::LoadBlueprintAssetDataFromPath(path) - loads info about blueprint assets by path. In editor mode i can get them, and then get GeneratedClass of them. When game is cooked there is "no blueprints" there is only GeneratedClass. So i can load GeneratedClass directly by adding "_C" to object path.
          Hey MadScorp, are you saying that you removed UObjectLibrary::LoadBlueprintAssetDataFromPath(path)? Did you use UObjectLibrary::LoadAssetDataFromPath instead?

          Comment


            #6
            Done code example here - https://answers.unrealengine.com/que...#answer-309155
            Pull Request - UE-13079: World Origin Shifting for Multiplayer. Make Arma Not War - TFAR.

            Comment

            Working...
            X