目錄
- 1 地圖加載流程
- 1.1 默認Experience的加載
- 1.2 加載角色
- 1.3 加載場景中的幾個傳送點
- 2 幾個內建類的筆記
- 2.1 UDataAsset
- 2.2 UAssetManager
純個人筆記,有錯誤歡迎指正,學習階段基本看到不會的就寫一寫,最后有時間會梳理整體結構
先看完了官方的演講
1 地圖加載流程
1.1 默認Experience的加載
??這里先不從GameInstance開始,中間的CommonUser等流程暫時不談(有點多暫時不想看0w0),編輯器默認地圖L_DefaultEditorOverview中沒有重載游戲模式,所以用項目默認的B_LyraGameMode。
??ALyraGameMode::InitGame()
// Wait for the next frame to give time to initialize startup settings
GetWorld()->GetTimerManager().SetTimerForNextTick(this, &ThisClass::HandleMatchAssignmentIfNotExpectingOne);
可見邏輯轉到了ALyraGameMode::HandleMatchAssignmentIfNotExpectingOne()
(這里走的默認分支)
void ALyraGameMode::HandleMatchAssignmentIfNotExpectingOne()
{...ExperienceId = FPrimaryAssetId(FPrimaryAssetType("LyraExperienceDefinition"), FName("B_LyraDefaultExperience"));ExperienceIdSource = TEXT("Default");...OnMatchAssignmentGiven(ExperienceId, ExperienceIdSource);
}
??之后的調用棧大概是
OnMatchAssignmentGiven(ExperienceId, ExperienceIdSource)->
void ULyraExperienceManagerComponent::SetCurrentExperience(ExperienceId)->
void ULyraExperienceManagerComponent::StartExperienceLoad()->
void ULyraExperienceManagerComponent::OnExperienceLoadComplete()
??過程大體是設置當前ExperienceId,異步加載Experience相關資源,調用加載完成的回調.
??OnExperienceLoadComplete()函數收集GameFeaturePluginURL,最終調用
UGameFeaturesSubsystem::Get().
LoadAndActivateGameFeaturePlugin(PluginURL,
FGameFeaturePluginLoadComplete::CreateUObject(this,
&ThisClass::OnGameFeaturePluginLoadComplete));
??觸發默認Feature的Action
這里記錄一下幾個Action函數的調用順序, 防止我忘了
在這個函數中:
void ULyraExperienceManagerComponent::OnExperienceFullLoadCompleted()
ActivateListOfActions的定義
auto ActivateListOfActions = [&Context](const TArray<UGameFeatureAction*>& ActionList){for (UGameFeatureAction* Action : ActionList){if (Action != nullptr){//@TODO: The fact that these don't take a world are potentially problematic in client-server PIE// The current behavior matches systems like gameplay tags where loading and registering apply to the entire process,// but actually applying the results to actors is restricted to a specific worldAction->OnGameFeatureRegistering();Action->OnGameFeatureLoading();Action->OnGameFeatureActivating(Context);}}};
逐一調用順序
自己的Actions先調用,再遍歷調用ActionSets
ActivateListOfActions(CurrentExperience->Actions);for (const TObjectPtr<ULyraExperienceActionSet>& ActionSet : CurrentExperience->ActionSets){if (ActionSet != nullptr){ActivateListOfActions(ActionSet->Actions);}}
三個多播順序
OnExperienceLoaded_HighPriority.Broadcast(CurrentExperience);OnExperienceLoaded_HighPriority.Clear();OnExperienceLoaded.Broadcast(CurrentExperience);OnExperienceLoaded.Clear();OnExperienceLoaded_LowPriority.Broadcast(CurrentExperience);OnExperienceLoaded_LowPriority.Clear();
1.2 加載角色
B_LyraDefaultExperience中:
SimplePawnData:
可以發現通過這個就找到了創建的金屬Pawn,而不是GameMode中的角色類(是其藍圖子類)
但是為什么這里的配置能夠生效呢?
因為ALyraGameMode重寫了這個實現:
APawn* ALyraGameMode::SpawnDefaultPawnAtTransform_Implementation(AController* NewPlayer, const FTransform& SpawnTransform){
...
if (UClass* PawnClass = GetDefaultPawnClassForController(NewPlayer)){if (APawn* SpawnedPawn = GetWorld()->SpawnActor<APawn>(PawnClass, SpawnTransform, SpawnInfo))
...
}UClass* ALyraGameMode::GetDefaultPawnClassForController_Implementation(AController* InController)
{if (const ULyraPawnData* PawnData = GetPawnDataForController(InController)){if (PawnData->PawnClass){return PawnData->PawnClass;}}
...
}const ULyraPawnData* ALyraGameMode::GetPawnDataForController(const AController* InController) const
{
...
return Experience->DefaultPawnData;
...
}
1.3 加載場景中的幾個傳送點
由場景中這個Actor控制:
生成邏輯沒什么該注意的,注意生成時傳入了LyraUserfacingExperienceDefinition類型的變量,Widget信息都是根據這個配置的。
主要看加載地圖:
可見信息都在LyraUserfacingExperienceDefinition中,例如這個下邊這個,可以看到
要去的地圖信息都有。
2 幾個內建類的筆記
2.1 UDataAsset
剛拿到項目無從下手,就去看了啟動默認地圖L_LyraFrontEnd,沒有重載GameMode,即用的項目設置的B_LyraGameMode,暫時先不看GameMode,然后基于演講去看了DefaultGameplayExperience,一路看過去
B_LyraFrontEnd_Experience->
ULyraExperienceDefinition->
UPrimaryDataAsset->
UDataAsset->
UObject
這時候我發現我對DataAsset沒什么了解,只好先去學習一下:
UCLASS(abstract, MinimalAPI, Meta = (LoadBehavior = "LazyOnDemand"))
class UDataAsset : public UObject
abstract:
MinimalAPI沒太看懂,大概是優化編譯相關的:
LoadBehavior
UPrimaryDataAsset:
UE5–PrimaryDataAsset資產包更新UpdateAssetBundleData源碼分析
看完這幾篇后我的理解這個類就是數據資產。
2.2 UAssetManager
暫時停留在使用層理解。
UE5 AssetManager類使用詳解
參考文章:
UE5 Lyra項目學習(零) 開篇&目錄