@BaseReality
So first thing is AI needs the PlayerState, removing the need for a PlayerState in AI seems to be a bit more involved, since the main issue is that the ability system component gets added to the PlayerState.
If you look at how AI gets spawned in LyraBotCreationComponent, all it’s doing is creating a controller based on the class set in BotControllerClass (this should have “NeedsPlayerState” bool on).
The player state then is listening for a OnExperienceLoaded event, in which it asks the GameMode for a PawnData, the GameMode then checks if the PlayerState has one assinged on its own PawnData Variable, and if not it returns the default for the Experience.
So, we need to intercept this function and give the AI player state another PawnData.
In my case I’ve been trying not to modify the Lyra Code, and instead making child classes of a lot of things to add and modify for my needs.
But here is a quick way if you don’t mind changing Lyra classes, all you have to do is go to LyraExperienceDefinition.h and add a variable
UPROPERTY(EditDefaultsOnly, Category=Gameplay)
TObjectPtr<const ULyraPawnData> DefaultAIPawnData;
Then in LyraGameMode.cpp find the function called GetPawnDataForController and replace this part
if (ExperienceComponent->IsExperienceLoaded())
{
const ULyraExperienceDefinition* Experience = ExperienceComponent->GetCurrentExperienceChecked();
if (Experience->DefaultPawnData != nullptr)
{
return Experience->DefaultPawnData;
}
// Experience is loaded and theres still no pawn data, fall back to the default for now
return ULyraAssetManager::Get().GetDefaultPawnData();
}
with this
EDIT
if (ExperienceComponent->IsExperienceLoaded())
{
const ULyraExperienceDefinition* Experience = ExperienceComponent->GetCurrentExperienceChecked();
if (InController != nullptr && InController->IsA<AAIController>() && Experience->DefaultAIPawnData != nullptr)
{
return Experience->DefaultAIPawnData;
}
else if (Experience->DefaultPawnData != nullptr)
{
return Experience->DefaultPawnData;
}
// Experience is loaded and theres still no pawn data, fall back to the default for now
return ULyraAssetManager::Get().GetDefaultPawnData();
}
Now you can add the AI PawnData class in the ExperienceDefinition
I’ll Try to remember to come back here once I find a more elegant way without changing Lyra Base Classes, pretty sure its fine if you make your child gameMode and PlayerState and add it there, I already have a custom child player state with custom attribute sets etc
Seems this is either an overlook on Epic or a future to add thing because they even call the PawnData “Hero”