栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

UE5 C++ 重要点

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

UE5 C++ 重要点

1.控制相关
springArm->bUsePawnControlRotation=true;
camera->bUsePawnControlRotation=false;


2.动画相关
做动画在蓝图里用TimeLine


3.延迟相关
C++里的延迟用FTimerHandle
.h里定义
FTimerHandle closeHandle;
.cpp 里使用
GetWorldTimerManager().SetTimer(closeHandle,this,&AStageDoor::DelayCloseDoor,2.0f);

GetWorldTimerManager().ClearTimer(closeHandle);//立即停止不去执行回调


4.生成Actor
.h
TSubclassOf BlueprintVar;

.cpp
UWorld* const World = GetWorld(); // get a reference to the world  
if (World)   
{  
   // if world exists  
   YourClass* YC = World->SpawnActor(BlueprintVar, SpawnLocation, SpawnRotation);  
} 


5.可以显示在editor中的点
UPROPORTY(EditAnywhere,meta=(MakeEditWidget=true))
FVector EndPoint;

6.粒子特效
组件用
UParticleSysyemComponent*
需要生成的用
UParticleSystem*

生成方式:
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(),UParticleSystem*,Location,Rotation,IsAutoDelete);

7.播放音效
音效右键创建 Sound Cue
代码播放:
USoundCue*

UGameplayStatics::PlaySound2D(this,USoundCue*,Volume)

8.类的继承相关,碰撞继承
父类:
virtual ClassName();
子类:
virtual ClassName() override;
子类有自己的构造函数,里面需不要调取父类的构造函数
子类的ClassName()需要调取父类的:
Super::ClassName();


9.想要HUD的UI里使用c++代码
在 项目名.Build.cs 里加入"UMG"

10.要想C++代码现实UI需要先创建个
PlayerController类
需要自己写BeginPlay();
之后在PlayerController类里添加下面的UI代码,创建BP
之后在世界场景设置里选择该BP


11.UI代码
//在Eidtor用引用UMG资源
UPROPERTY(...)
TSubclssOf HUDOverlayAsset;
//之后代码使用
UPROPERTY(...)
UUserWidget* HUDOverlay;

if(HUDOverlayAsset;)
{
           HUDOverlay= CreateWidget(this,HUDOverlayAsset);
    HUDOverlay->AddToViewport();
    HUDOverlay->SetVisibility(ESlateVisibility::Visible);
}


12.碰撞检测里的OtherActor可以转化成需要的类,类似GetComponent
类名* aaa=Cast<类名>(OtherActor);
if(aaa)
{
    aaa->....
}


12.UE4中的枚举
UENUM(BlueprintType)
enum class EMovementStatus : uint8
{
    EMS_Normal UMETA(DisplayName = "Normal"),
    EMS_Sprinting UMETA(DisplayName = "Spriting"),

    EMS_Max UMETA(DisplayName = "Default Max")
}
枚举类型前面一定要加E否则会报错

UPROPERTY(...)
 EMovementStatus  MovementStatus;


13.现实debug球
UKismetSystemLibrary::DrawDebugSphere(this,Location,Radius,片段数量,FColor,显示时间,厚度)


14.TArray positions;

for(auto pos : positions)
{
}

15.想用AAIController
必须要在build.cs里加
"AIModule"

16.局部骨骼碰撞
CombatCollision =CreateDefaultSubobject(TEXT("CombatCollision"));
CombatCollision->AttachToComponent(GetMesh(),FAttachmentTransformforRules::SnapToTargetIncludingScale,FName("EnemySocket"));

需要在骨骼处右键添加骨骼插槽
用AttachToComponent而不是SetupAttachment

17.插值转向目标,写在Tick里
FVector Target=CombatTarget->GetActorLocation();
FRotator LookAtRotation=UKismetMathLibrary::FindLookAtRotation(GetActorLocation(),Target);
FRotator LookAtRotationYaw = FRotator(0.0f,LookAtRotation.Yaw,0.f);
FRotator InterpRotation =FMath::RInterpTo(GetActorRotation(),LookAtRotationYaw,DeltaTime,InterpSpeed);
SetActorRotation(InterpRotation);

18.AActor下面有用来接收伤害的函数,不需要调用Super
virtual float TakeDamage(float DamageAmount,struct FDamageEvent const & DamageEvent,class AController * EventInstigator,AActor * DamageCauser)  override  的重载函数
施加伤害的全局函数
UGameplayStatics::ApplyDamage(AActor * DamagedActor,float BaseDamage,AController * EventInstigator,AActor * DamageCauser, TSubclassOf< class UDamageType > DamageTypeClass)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/902306.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号