add c++ to tick?

Whilst itemA and itemB are declared for the ‘FollowActor’ function, they are not declared for the ‘Tick’ function. Somewhere, you would need a declaration of: -


AStaticMeshActor* itemA
AStaticMeshActor* itemB


If you do this within the ‘Tick’ function, then you would also need some extra code to get the actors you want to move as the code above would be ‘null’. Alternatively, you can put this in the header file. If you’ve created your actors within this class, then this is probably the easiest. However, if you did do this, you need to change the names of ‘itemA’ and ‘itemB’ within the ‘FollowActor’ function as they would clash with the header declared variables; maybe call them ‘Leader’ and ‘Follower’.

.h file


UFUNCTION(BlueprintCallable, Category = "VPCONSTRAINTS")
static void FollowActor(AStaticMeshActor* Follower, AStaticMeshActor* Leader);

UPROPERTY()
AStaticMeshActor* itemA

UPROPERTY()
AStaticMeshActor* itemB


.cpp file


void ACntrls::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
// check that both pointers have been assigned before calling the function
if ((itemA != NULL) && (itemB != NULL))
{
FollowActor(itemA, itemB);
}
}


void ACntrls::FollowActor(AStaticMeshActor* Follower, AStaticMeshActor* Leader)
{

Follower->SetActorLocation(Leader->GetActorLocation());
Follower->SetActorRotation(Leader->GetActorRotation());

}