You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the posting. It all worked except for the indicated note (got it working with the BP extension, as well, but not pure C++). Did a little digging into engine to see what the bAutoRegisterAllPawnsAsSources flag was controlling.
In AIPerceptionSystem.cpp: ShouldAutoRegisterAllPawnsAsSources() triggers RegisterSource(SenseID, Pawn).
So I just added the equivalent method call to BeginPlay() which registers the player pawn as a new source to monitor. AIDebugger now shows player being tracked while other pawns ignored.
// RegisterSource: Should probably validate GetWorld and PerceptionSystem???
UAIPerceptionSystem::GetCurrent(GetWorld())->RegisterSource(*this);
}
...
I found in some cases the AIPerceptionSystem was not fully initialized on first spawn of the player. Not sure how to properly address that one but there is a simple workaround using a timer.
The timer runs a few ticks before the IsSenseInstantiated becomes true. The bAutoRegisterAllPawnsAsSources=true switch probably allows the engine to fully instantiate UAIPerceptionSystem prior to any spawning any pawns because it knows what's coming. Whereas, setting bAutoRegisterAllPawnsAsSources=false and then manually adding Senses/Sources with classes may cause the AIPerceptionSystem to finalize after the designated classes are loaded???
FWIW
The text was updated successfully, but these errors were encountered:
Thanks for the posting. It all worked except for the indicated note (got it working with the BP extension, as well, but not pure C++). Did a little digging into engine to see what the bAutoRegisterAllPawnsAsSources flag was controlling.
ShouldAutoRegisterAllPawnsAsSources() returns bAutoRegisterAllPawnsAsSources
In AIPerceptionSystem.cpp: ShouldAutoRegisterAllPawnsAsSources() triggers RegisterSource(SenseID, Pawn).
So I just added the equivalent method call to BeginPlay() which registers the player pawn as a new source to monitor. AIDebugger now shows player being tracked while other pawns ignored.
PlayerCharacter.h >>
...
virtual void BeginPlay() override;
...
PlayerCharacter.cpp >>
...
void APlayerCharacter::BeginPlay()
{
Super::BeginPlay();
}
...
I found in some cases the AIPerceptionSystem was not fully initialized on first spawn of the player. Not sure how to properly address that one but there is a simple workaround using a timer.
void APlayerCharacter::BeginPlay()
{
Super::BeginPlay();
}
void APlayerCharacter::RegisterSourceCheck()
{
// Check IsSenseInstantiated.
if (UAIPerceptionSystem::GetCurrent(GetWorld())->IsSenseInstantiated(UAISense::GetSenseID<UAISense_Sight>()))
{
// RegisterSource.
UAIPerceptionSystem::GetCurrent(GetWorld())->RegisterSource(*this);
}
The timer runs a few ticks before the IsSenseInstantiated becomes true. The bAutoRegisterAllPawnsAsSources=true switch probably allows the engine to fully instantiate UAIPerceptionSystem prior to any spawning any pawns because it knows what's coming. Whereas, setting bAutoRegisterAllPawnsAsSources=false and then manually adding Senses/Sources with classes may cause the AIPerceptionSystem to finalize after the designated classes are loaded???
FWIW
The text was updated successfully, but these errors were encountered: