CreateDefaultSubobject
1.创建组件
.h
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UActorComponent *MyComp;
.cpp
MyComp = CreateDefaultSubobject<UActorComponent>("MyComp");
2.获取controller
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GWorld, 0);
3.获取controller pawn
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GWorld, 0);
myPawn = PlayerController->GetPawn();
4.Pawn转自己的类型
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GWorld, 0);
myPawn = PlayerController->GetPawn();
Axxx* xxx = Cast<Axxx>(myPawn);
5.LineTraceSingleByChannel的使用
FVector Start = ;
FVector End = ;
FHitResult OutHitResult;
FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(DestopPresenceCursorTrace), true, this);
bool bSuccess = GetWorld()->LineTraceSingleByChannel(OutHitResult, Start, End, ECC_Visibility, QueryParams);
6.打印到屏幕
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("bSuccess : %d"), (int)bSuccess));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("string : %s"), *mystring);
|