news 2026/2/18 5:53:00

ue5 自定义 actor ac++ actor 用法实战

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ue5 自定义 actor ac++ actor 用法实战

目录

蓝图中调用c++ actor

c++创建类:

MetahumancharacterHeiXi\MyActor.h

MetahumancharacterHeiXi\MyActor.cpp


蓝图中调用c++ actor

  • 打开Content Drawer

  • 找到你这个 C++ 类:

    MyActor

  • 右键 MyActor → Create Blueprint Class Based on MyActor

  • 命名:BP_MyActor

然后把BP_MyActor 拖进关卡,

然后:

c++创建类:

MetahumancharacterHeiXi\MyActor.h

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "Animation/AnimationAsset.h" #include "Components/SkeletalMeshComponent.h" #include "MyActor.generated.h" UCLASS() class METAHUMANCHARACTERHEIXI_API AMyActor : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AMyActor(); UPROPERTY(EditAnywhere, BlueprintReadWrite) USkeletalMeshComponent* Body_comp; UPROPERTY(EditAnywhere, BlueprintReadWrite) UAnimationAsset* TalkAnim; UFUNCTION(BlueprintCallable, Category = "Talk") void PlayTalkAnim(USkeletalMeshComponent* TargetMesh); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; };

MetahumancharacterHeiXi\MyActor.cpp

// Fill out your copyright notice in the Description page of Project Settings. #include "MyActor.h" #include "UObject/ConstructorHelpers.h" // Sets default values AMyActor::AMyActor() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; static ConstructorHelpers::FObjectFinder<UAnimationAsset> AnimObj( TEXT("/Game/anim_new/talk03.talk03") ); UE_LOG(LogTemp, Error, TEXT("load Game/anim_new/talk03.talk03 ok")); if (AnimObj.Succeeded()) { TalkAnim = AnimObj.Object; } if (!Body_comp) { // 找到蓝图里第一个 SkeletalMeshComponent Body_comp = FindComponentByClass<USkeletalMeshComponent>(); if (!Body_comp) { UE_LOG(LogTemp, Warning, TEXT("找不到 BodyMesh!")); } } UE_LOG(LogTemp, Error, TEXT("BodyMesh ok")); } void AMyActor::PlayTalkAnim(USkeletalMeshComponent* targetMesh) { UE_LOG(LogTemp, Error, TEXT("PlayTalkAnim 111")); if (!targetMesh || !TalkAnim) { UE_LOG(LogTemp, Warning, TEXT("Body or TalkAnim is null")); return; } UE_LOG(LogTemp, Error, TEXT("PlayTalkAnim 222")); // 对应蓝图:Set Global Anim Rate Scale targetMesh->GlobalAnimRateScale = 1.f; // 必须切换到 Single Node targetMesh->SetAnimationMode(EAnimationMode::AnimationSingleNode); UE_LOG(LogTemp, Error, TEXT("PlayTalkAnim 333")); // 对应蓝图:Play Animation targetMesh->PlayAnimation(TalkAnim, true); // true = Looping } // Called when the game starts or when spawned void AMyActor::BeginPlay() { Super::BeginPlay(); } // Called every frame void AMyActor::Tick(float DeltaTime) { Super::Tick(DeltaTime); }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/17 20:28:35

Escrcpy云测试平台集成:构建高效Android设备管理方案

Escrcpy云测试平台集成&#xff1a;构建高效Android设备管理方案 【免费下载链接】escrcpy &#x1f4f1; Graphical Scrcpy to display and control Android, devices powered by Electron. | 使用图形化的 Scrcpy 显示和控制您的 Android 设备&#xff0c;由 Electron 驱动。…

作者头像 李华
网站建设 2026/2/14 2:21:04

Windows平台socat终极配置指南:5分钟快速部署网络数据转发

Windows平台socat终极配置指南&#xff1a;5分钟快速部署网络数据转发 【免费下载链接】socat-windows unofficial windows build of socat http://www.dest-unreach.org/socat/ 项目地址: https://gitcode.com/gh_mirrors/so/socat-windows 快速入门&#xff1a;从零配…

作者头像 李华
网站建设 2026/2/3 3:14:20

D3KeyHelper暗黑3宏工具终极指南:新手5分钟快速上手

D3KeyHelper暗黑3宏工具终极指南&#xff1a;新手5分钟快速上手 【免费下载链接】D3keyHelper D3KeyHelper是一个有图形界面&#xff0c;可自定义配置的暗黑3鼠标宏工具。 项目地址: https://gitcode.com/gh_mirrors/d3/D3keyHelper 还在为暗黑3中重复繁琐的技能操作而头…

作者头像 李华
网站建设 2026/2/17 4:41:35

通义千问2.5-7B-Instruct保姆级教程:从零开始GPU部署实操

通义千问2.5-7B-Instruct保姆级教程&#xff1a;从零开始GPU部署实操 通义千问 2.5-7B-Instruct 是阿里 2024 年 9 月随 Qwen2.5 系列一同发布的 70 亿参数指令微调模型&#xff0c;定位“中等体量、全能型、可商用”。该模型在性能、效率和易用性之间实现了良好平衡&#xff…

作者头像 李华
网站建设 2026/2/18 5:44:03

从零实现干净系统状态:Vivado完整卸载方案

从零开始构建纯净开发环境&#xff1a;彻底卸载 Vivado 的实战指南 你有没有遇到过这样的情况&#xff1f; 刚下载好最新版 Vivado&#xff0c;满怀期待地点击安装&#xff0c;结果弹出一条令人窒息的提示&#xff1a;“检测到旧版本存在&#xff0c;无法继续安装。” 或者更…

作者头像 李华
网站建设 2026/2/16 8:17:23

MediaPipe Hands高级教程:自定义手势识别模型训练

MediaPipe Hands高级教程&#xff1a;自定义手势识别模型训练 1. 引言 1.1 AI 手势识别与追踪 随着人机交互技术的不断发展&#xff0c;基于视觉的手势识别已成为智能设备、虚拟现实、增强现实和智能家居等领域的关键技术之一。传统触摸或语音控制方式在特定场景下存在局限性…

作者头像 李华