- Created a new project by selecting the Third Person C++ template.
- Duplicated the existing “ThirdPersonCharacter”.
- Inserted
Female
into the Actor tags of “ThirdPersonCharacter2”.
- Changed the skeletal mesh of ThirdPersonCharacter2 to “SK_Mannequin_Female”.
- Inserted
Male
into the Actor tags of ThirdPersonCharacter.
- The C++ classes of ThirdPersonCharacter and ThirdPersonCharacter2 as seen in the World Outliner are
MyProjectCharacter.cpp
and MyProjectCharacter.h
as seen in the Solution Explorer in Microsoft Visual Studio Community 2019.
- In
MyProjectCharacter.cpp
I wrote 2 headers under the existing headers:
#include "Kismet/GameplayStatics.h" // Print to the log at runtime.
#include "Templates/SubclassOf.h" //GetAllActorsOfClassWithTag?
void AMyProjectCharater::jump()
{
Super::jump();// Extend existing character movement functionality?
TArray<AActor*> outActors = TArray<AActor*>();// is empty.
TSubclassOf<AMyProjectCharacter*> myActorClass = TSubclassOf<AMyProjectCharacter*>(this);// MyActorClass should be a subclass of or the same class as this class?
UGameplayStatics::GetAllActorsOfClassWithTag
(
GetWorld(),
myActorClass,//?
FName("Female"),
&outActors
);
if (outActors.Num() > 0)
{
UKismetSystemLibrary::PrintString
(
GetWorld(),
outActors[0]->GetName(),
true,
true,
FLinearColor(0.0, 0.66, 1.0),
60.0f
);
}
}
Use AMyProjectCharater::StaticClass()
or this->GetClass()
as actor class.
this
is not a class it’s an instance.
Constructing a TSubclassOf doesn’t make sense.
1 Like