The downside of async loading in Blueprint is that we can’t pass in additional parameters in our own Delegate as easily as we did in C++ example above where we pass in the FVector for spawn location. Blueprint Async Loading ExampleĪsync loading is a bit easier in Blueprint as there is a neat little node available. USMonsterData* MonsterData = Cast(Manager->GetPrimaryAssetObject(LoadedId)) ĪActor* NewBot = GetWorld()->SpawnActor(MonsterData->MonsterClass, SpawnLocation, FRotator::ZeroRotator) Įxample taken from open-source Action Roguelike. UAssetManager* Manager = UAssetManager::GetIfValid() The OnMonsterLoaded Function once load has completed: void ASGameModeBase::OnMonsterLoaded(FPrimaryAssetId LoadedId, FVector SpawnLocation) Manager->LoadPrimaryAsset(MonsterId, Bundles, Delegate) Will call function 'OnMonsterLoaded' once it's complete.įStreamableDelegate Delegate = FStreamableDelegate::CreateUObject(this, &ASGameModeBase::OnMonsterLoaded, MonsterId, SpawnLocation) Delegate with parameters we need once the asset had been loaded such as the Id we loaded and the location to spawn at. ![]() Locations array from omitted part of code (see github) If (UAssetManager* Manager = UAssetManager::GetIfValid())įPrimaryAssetId MonsterId = SelectedMonsterRow->MonsterId In the example below I pass in the loaded Id and a vector spawn location. Loading in C++ works by creating a Delegate with your own set of parameters you wish to pass along with it. So I’d like to share some code examples (also available on GitHub) on how to async load your assets. This aspect is what I could find the least information on when diving into Asset Manager. Return FPrimaryAssetId(ItemType, GetFName()) FPrimaryAssetId ULZItemData::GetPrimaryAssetId() const You may just want to return the name of your asset file.īelow is an example implementation of setting up the Id for a DataAsset. (the Id combines the Type:Name) You won’t be manually typing each Id, instead you can override the GetPrimaryAssetId on your asset in C++ to handle how you want Ids to be generated/handled. This is how you will point to specific assets that you want to load, and is similar to soft references you may be used to.įor example, my ships are of type ShipConfig and one of the Ids that point to a specific data asset could look like ShipConfig:MyPirateShip. Primary Asset Id & Type are both glorified FNames and categorize/identify the assets. You can think of it as descriptors, to describe the AI minion (hitpoints, abilities to grant, actor class to spawn, behavior tree to use) rather than its actual logic and brains. You can include Actor classes to spawn, Abilities to grant, UI names, Icons, etc. These assets will purely hold data and no functional logic. UPrimaryDataAsset (UDataAsset)ĭataAsset class already set up to support Asset Manager. Return FPrimaryAssetId("Monsters", GetFName()) Īnother example of a Primary Asset is a Weapon DataAsset that holds variables and soft references such as the weapon Actor Class, damage type, Icon texture, UI Name, Rarity, etc.ĭata Asset Examples of ‘Ship Configurations’ in WARPSQUAD. UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "UI")įPrimaryAssetId GetPrimaryAssetId() const override * Actions/buffs to grant this Monster */ ![]() UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Spawn Info") UCLASS()Ĭlass ACTIONROGUELIKE_API USMonsterData : public UPrimaryDataAsset The actions are its abilities to be granted. ![]() The use-case is a basic configuration for an AI to be spawned into the world. Here is an example of a PrimaryAsset with MonsterData from my ActionRoguelike on GitHub. Virtual FPrimaryAssetId GetPrimaryAssetId() const Īn example of a PrimaryAsset is an AI configuration asset that holds info about a specific monster along with which Actor to spawn for this AI, some attributes, abilities, and perhaps some UI stuff like name and icon. ![]() * If this is valid, the object can be referenced by identifier using the AssetManager * Assets that need to be globally referenced at runtime should return a valid Identifier. * Returns an Type:Name pair representing the PrimaryAssetId for this object. You can turn these ‘secondary assets’ (Everything is considered a Secondary Asset by default) into Primary Assets by overriding GetPrimaryAssetId() from UObject.h: /** These are the assets you will manage and the system will load/unload any referenced content (also known as ‘secondary assets’) such as meshes and textures. Your project must define certain classes as Primary Assets (these may often be derived from PrimaryDataAsset but can derive from any UObject). Instead I’ll use this article to be more example-driven and from my personal perspective and use-cases. I recommend reading the official documentation page as I’ll try not to repeat too much of what is already explained there.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |