I’m trying to setup a simple AI implemented in C++, and after not being able to make it do anything I added some functions to print out messages in the AI’s tick function to see if anything is working. But neither my UE_LOG or AddOnScreenDebugMessage function ever gets called, even though I have bCanEverTick and bStartWithTickEnabled set to true. Everything compiles without errors.
Here’s the constructor:
ABaseAI::ABaseAI(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
}
And my Tick function:
void ABaseAI::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
UE_LOG(LogTemp, Warning, TEXT("Your message"));
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Tick"));
}
I placed the AI in my level but nothing gets written to the output log nor printed on the screen. I tried putting those statements inside of the constructor and on the BeginPlay() function as well, but nothing happened. ABaseAI derives from another of my own classes, ABaseCharacter which derives from the default ACharacter. The AI uses my own simple controller, but none of its functions ever seem to get called either.
Hey MuchToLearn-
Does the ABaseCharacter Tick() function print properly or do you have the same behavior if you add the same code to it? I tried to match your setup with ACharacter->ABaseCharacter->ANewChar as my class hierarchy setup but my on screen debug message printed as expected each frame.
Code used to test
//constructor
ANewChar::ANewChar()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
}
//Tick function
void ANewChar::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 4, FColor::Red, TEXT("Stuff"));
}
}
If possible could you post your project or a sample project with this issue for me to test directly? For privacy concerns you can upload your project and then send me a PM on the forums with a link to download the project.
Cheers
Thank you for the reply, adding the print statements to ABAseCharacter’s Tick method did not work either. However, I created a blank project and extended ACharacter, the tick function in the new project worked as expected.
I went back to my project and got a bunch of unresolved external symbol compile errors (LNK2001) in ABaseCharacter and the controller. I’ve got them for overridden functions like Possess() and for all of my own. I don’t understand why VS is having linking issues though, all of my functions are defined in the header file and included.
I think I’ll start over with the C++ files.