UEC++ 创建自定义类型案例
一子弹类型// .h文件 #include CoreMinimal.h #include GameFramework/Actor.h #include Components/SphereComponent.h #include GameFrameWork/ProjectileMovementComponent.h #include MyActor.generated.h // ... UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUStaticMeshComponent Sphere; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUSphereComponent SphereCollision; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUProjectileMovementComponent ProjectileMovement;// .cpp文件 AMyActor::AMyActor() { PrimaryActorTick.bCanEverTick true; Sphere CreateDefaultSubobjectUStaticMeshComponent(TEXT(Sphere)); SphereCollision CreateDefaultSubobjectUSphereComponent(TEXT(SphereCollision)); ProjectileMovement CreateDefaultSubobjectUProjectileMovementComponent(TEXT(ProjectileMovement)); static ConstructorHelpers::FObjectFinderUStaticMesh StaticSphereMesh(TEXT(/Engine/BasicShapes/Sphere.Sphere)); RootComponent Sphere; SphereCollision-SetupAttachment(RootComponent); ProjectileMovement-SetUpdatedComponent(RootComponent); Sphere-SetStaticMesh(StaticSphereMesh.Object); ProjectileMovement-InitialSpeed 500.0; ProjectileMovement-MaxSpeed 2000.0; }二带有增强输入的角色类型// .h文件 #include CoreMinimal.h #include InputActionValue.h #include EnhancedInputComponent.h #include EnhancedInputSubsystems.h #include GameFramework/Controller.h #include GameFramework/SpringArmComponent.h #include Camera/CameraComponent.h #include GameFramework/Character.h #include GameFramework/CharacterMovementComponent.h #include MyCharacter.generated.h class UInputAction; class UInputMappingContext; // ... public: UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUSpringArmComponent SpringArm; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUCameraComponent Camera; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUInputMappingContext DefaultMappingContext; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUInputAction MoveAction; UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtrUInputAction LookAction; public: void Move(const FInputActionValue value); void Look(const FInputActionValue value); // ...// .cpp文件 AMyCharacter::AMyCharacter() { PrimaryActorTick.bCanEverTick true; SpringArm CreateDefaultSubobjectUSpringArmComponent(TEXT(SpringArm)); Camera CreateDefaultSubobjectUCameraComponent(TEXT(Camera)); SpringArm-TargetArmLength 400.0f; SpringArm-bUsePawnControlRotation true; SpringArm-SetupAttachment(RootComponent); Camera-SetupAttachment(SpringArm); //控制器只影响相机不影响角色 bUseControllerRotationPitch false; bUseControllerRotationRoll false; bUseControllerRotationYaw false; GetCharacterMovement()-bOrientRotationToMovement true; } void AMyCharacter::BeginPlay() { Super::BeginPlay(); if (auto PlayerController CastAPlayerController(Controller)) if (auto Subsystem ULocalPlayer::GetSubsystemUEnhancedInputLocalPlayerSubsystem(PlayerController-GetLocalPlayer())) Subsystem-AddMappingContext(DefaultMappingContext, 0); } void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); if (auto EnhancedInputComponent CastCheckedUEnhancedInputComponent(PlayerInputComponent)) { EnhancedInputComponent-BindAction(MoveAction, ETriggerEvent::Triggered, this, AMyCharacter::Move); EnhancedInputComponent-BindAction(LookAction, ETriggerEvent::Triggered, this, AMyCharacter::Look); } } void AMyCharacter::Move(const FInputActionValue value) { FVector2D MovementVector value.GetFVector2D(); if (Controller) { const FRotator Rotation Controller-GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); const FVector FowardDirection FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); const FVector RightDirection FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); AddMovementInput(FowardDirection, MovementVector.Y); AddMovementInput(RightDirection, MovementVector.X); } } // 5.7使用IMC_Default 和 IMC_MouseLook 将按键和鼠标操作分开 // IMC_Default → 按键操作移动、跳跃、冲刺、交互等 // IMC_MouseLook → 鼠标操作视角旋转 void AMyCharacter::Look(const FInputActionValue value) { FVector2D LookAxisVector value.GetFVector2D(); if (Controller) { AddControllerYawInput(LookAxisVector.X); AddControllerPitchInput(LookAxisVector.Y); } }

相关新闻

智谱 GLM Coding Plan 2026年7月31日套餐变动分析报告

智谱 GLM Coding Plan 2026年7月31日套餐变动分析报告

智谱 GLM Coding Plan 2026年7月31日套餐变动分析报告分析日期:2026年8月2日 数据来源:智谱官方文档 (docs.bigmodel.cn)、IT之家、新浪财经、CreditsPlan.cn、CSDN一、背景概述 2026年7月30日,智谱正式将 GLM Coding Plan 套餐改版升级&…

2026/10/28 11:53:38 阅读更多 →
【2024年AI编程工具终极榜单】:12款经过372小时实测的生产力神器,开发者私藏清单首次公开

【2024年AI编程工具终极榜单】:12款经过372小时实测的生产力神器,开发者私藏清单首次公开

更多请点击: https://intelliparadigm.com 第一章:AI编程工具推荐 现代AI开发已不再依赖单一IDE,而是由协同工作的工具链支撑——从代码补全、调试优化到模型微调与部署,每类工具都承担着关键角色。以下推荐的工具均经过生产环境…

2026/11/2 1:03:44 阅读更多 →
Spring Boot 4.x安全监控方案解析与实践

Spring Boot 4.x安全监控方案解析与实践

1. 为什么Spring Boot 4.x需要全新的安全监控方案?在微服务架构深度普及的今天,系统的可观测性已经成为保障服务稳定性的生命线。Spring Boot 4.x版本对监控体系进行了重大重构,其中最核心的变化就是引入了ObservationFilterChainDecorator机…

2026/10/26 17:47:31 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/2 0:25:10 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/2 10:46:11 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/2 10:47:40 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/2 1:16:51 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/2 10:46:31 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/2 10:46:26 阅读更多 →

日新闻

周新闻

月新闻