Ok I made some debugging, I found that Event Begin Play
is triggered correctly for all AI Controlled Tank_BP, but the issue is LeftTrack & RightTrack are not keeped in memory
See my code for TankMovementComponent.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "TankMovementComponent.h"
#include "TankTrack.h"
void UTankMovementComponent::Initialise(UTankTrack* LeftTrackToSet, UTankTrack* RightTrackToSet)
{
LeftTrack = LeftTrackToSet;
RightTrack = RightTrackToSet;
UE_LOG(LogTemp, Warning, TEXT("Mouvement Tracks left/right: %s & %s are Set for Tank %s"),
*(LeftTrack->GetName()), *(RightTrack->GetName()), *(GetOwner()->GetName()))
}
void UTankMovementComponent::IntentMoveForward(float Throw)
{
if (!LeftTrack || !RightTrack) {
UE_LOG(LogTemp, Warning, TEXT("Missings Track(s) to IntentMoveForward for Tank %s"),
*(GetOwner()->GetName()))
return;
}
LeftTrack->SetThrottle(Throw);
RightTrack->SetThrottle(Throw);
// TODO prevent double speed due to dual control use
}
void UTankMovementComponent::IntentTurnRight(float Throw)
{
if (!LeftTrack || !RightTrack) {
return;
}
auto Name = GetName();
LeftTrack->SetThrottle(Throw);
RightTrack->SetThrottle(Throw * -1.f);
// TODO prevent double speed due to dual control use
}
void UTankMovementComponent::RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed)
{
// No need to call Super as we're replacing the functionnality
auto TankForward = GetOwner()->GetActorForwardVector().GetSafeNormal();
auto AIForwardIntention = MoveVelocity.GetSafeNormal();
auto ForwardThrow = FVector::DotProduct(TankForward, AIForwardIntention);
UE_LOG(LogTemp, Warning, TEXT("AI forward throw %f"), ForwardThrow);
IntentMoveForward(ForwardThrow);
}
output log
LogBlueprintUserMessages: [Tank_BP_C_0] Tank_BP BeginPlay Event Triggered
LogTemp: Warning: Mouvement Tracks left/right: LeftTrack & RightTrack are Set for Tank Tank_BP_C_0
LogBlueprintUserMessages: [Tank_BP_1707] Tank_BP BeginPlay Event Triggered
LogTemp: Warning: Mouvement Tracks left/right: LeftTrack & RightTrack are Set for Tank Tank_BP_1707
LogBlueprintUserMessages: [Tank_BP2_3030] Tank_BP BeginPlay Event Triggered
LogTemp: Warning: Mouvement Tracks left/right: LeftTrack & RightTrack are Set for Tank Tank_BP2_3030
PIE: Play in editor start time for /Game/_Levels/UEDPIE_0_BattleGround -0.199
LogBlueprintUserMessages: Late PlayInEditor Detection: Level '/Game/_Levels/BattleGround.BattleGround:PersistentLevel' has LevelScriptBlueprint '/Game/_Levels/BattleGround.BattleGround:PersistentLevel.BattleGround' with GeneratedClass '/Game/_Levels/BattleGround.BattleGround_C' with ClassGeneratedBy '/Game/_Levels/BattleGround.BattleGround:PersistentLevel.Ba
ttleGround'
LogTemp: Warning: AI forward throw 0.998884
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP2_3030
LogTemp: Warning: AI forward throw 0.744032
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP_1707
LogTemp: Warning: AI forward throw 0.998884
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP2_3030
LogTemp: Warning: AI forward throw 0.743949
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP_1707
LogTemp: Warning: AI forward throw 0.998885
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP2_3030
LogTemp: Warning: AI forward throw 0.742295
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP_1707
LogTemp: Warning: AI forward throw 0.998886
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP2_3030
LogTemp: Warning: AI forward throw 0.741792
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP_1707
LogTemp: Warning: AI forward throw 0.998886
LogTemp: Warning: Missings Track(s) to IntentMoveForward for Tank Tank_BP2_3030
LogTemp: Warning: AI forward throw 0.741213