当前位置: 首页 > news >正文

UE5 C++ UGameInstance 功能、作用及应用

# UE5 C++ UGameInstance  功能及作用
 


网上有很多文章介绍,例如在游戏中只有一个实例,换关卡不会丢失等。暂时省略。

#  UE5 C++ UGameInstance  应用


## 应用一,UE5 C++ UGameInstance  里监听player创建事件


UWebSocketGameInstance.h里的定义

UCLASS()
class MYUE521_API UUWebSocketGameInstance : public UGameInstance
{GENERATED_BODY()public:virtual void Init() override;virtual void Shutdown() override;void OnPlayerCreated(ULocalPlayer* player);
}

说明:

  1.  Init()方法是在UGameInstance.h里定义的。源码里的注解是允许在这里自定义一些实现
  2. Shutdown()方法是在UGameInstance.h里定义的。源码里的注解是允许在这里自定义一些清理工作
  3. void OnPlayerCreated(ULocalPlayer* player) 方法是我自己定义的方法,用来监听创建player以后执行的方法

下面来看一下实现UWebSocketGameInstance.cpp里

void UUWebSocketGameInstance::Init() {Super::Init();OnLocalPlayerAddedEvent.AddUObject(this,&UUWebSocketGameInstance::OnPlayerCreated);}void UUWebSocketGameInstance::Shutdown() {//先写自定义的清理工作Super::Shutdown();
}void UUWebSocketGameInstance::OnPlayerCreated(ULocalPlayer* player) {UE_LOG(LogTemp, Warning, TEXT("%s plaer is created"), *FString(__FUNCTION__));
}

说明:

  1.  UE5里的事件绑定,这里绑定到自定义的OnPlayerCreated 方法里
  2. 触发事件OnLocalPlayerAddedEvent的位置在GameInstance.cpp里有AddLocalPlayer(ULocalPlayer* NewLocalPlayer, FPlatformUserId UserId)方法里有OnLocalPlayerAddedEvent.Broadcast(NewLocalPlayer); 通过广播通知


## 应用二,UE5 C++ UGameInstance  里player转成目标Characher的方法


ACharacter* character = UGameplayStatics::GetPlayerCharacter(this->GetWorld(), 0);
Amyue521Character* character2 = Cast<Amyue521Character>(character);
if (character2 == nullptr) {UE_LOG(LogTemp, Warning, TEXT("%s  1强制类型转换成Amyue521Character失败"), *FString(__FUNCTION__));
}
else {UE_LOG(LogTemp, Warning, TEXT("%s  1强制类型转换成Amyue521Character成功"), *FString(__FUNCTION__));
}

## 应用三,UE5 C++ UGameInstance  里一些方法罗列

/** Returns number of fully registered local players */
int32					GetNumLocalPlayers() const;/** Returns the local player at a certain index, or null if not found */
ULocalPlayer*			GetLocalPlayerByIndex(const int32 Index) const;/** Returns the first local player, will not be null during normal gameplay */
ULocalPlayer*			GetFirstGamePlayer() const;/** Returns the player controller assigned to the first local player. If World is specified it will search within that specific world */
APlayerController*		GetFirstLocalPlayerController(const UWorld* World = nullptr) const;/** Returns the local player assigned to a physical Controller Id, or null if not found */
ULocalPlayer*			FindLocalPlayerFromControllerId(const int32 ControllerId) const;/** Returns the local player assigned to this platform user id, or null if not found */
ULocalPlayer* FindLocalPlayerFromPlatformUserId(const FPlatformUserId UserId) const;/** Returns the local player that has been assigned the specific unique net id */
ULocalPlayer*			FindLocalPlayerFromUniqueNetId(FUniqueNetIdPtr UniqueNetId) const;
ULocalPlayer*			FindLocalPlayerFromUniqueNetId(const FUniqueNetId& UniqueNetId) const;
ULocalPlayer*			FindLocalPlayerFromUniqueNetId(const FUniqueNetIdRepl& UniqueNetId) const;/** Returns const iterator for searching list of local players */
TArray<ULocalPlayer*>::TConstIterator	GetLocalPlayerIterator() const;/** Returns reference to entire local player list */
const TArray<ULocalPlayer*> &			GetLocalPlayers() const;

#  UE5 C++ UGameInstance  其他

待补充

相关文章:

UE5 C++ UGameInstance 功能、作用及应用

# UE5 C UGameInstance 功能及作用 网上有很多文章介绍&#xff0c;例如在游戏中只有一个实例&#xff0c;换关卡不会丢失等。暂时省略。 # UE5 C UGameInstance 应用 ## 应用一&#xff0c;UE5 C UGameInstance 里监听player创建事件 UWebSocketGameInstance.h里的定义 …...

NodeJs-http模块

目录 一、概念二、请求报文的组成三、响应报文的组成四、创建http服务4.1 操作步骤4.2 注意事项 五、获取 HTTP 请求报文5.1 获取请求报文5.2 提取路径和查询字符串 六、设置 HTTP 响应报文七、MIME设置资源类型 一、概念 HTTP&#xff08;hypertext transport protocol&#…...

翻译句子 前面的路是非常狭窄的 不能翻译成 the ahead of road is narrow 的原因

翻译句子 前面的路是非常狭窄的。The road ahead is very narrow. 可以将句子翻译成 “The ahead of road is narrow.”&#xff0c;但这个翻译可能不太符合英语的表达习惯。更常见的表达方式是 “The road ahead is narrow.”&#xff0c;这样更符合英语的语法和习惯用法。 …...

NTT功能与实现

NTT的基础功用与拓展功能: 1.evaluate和interpolate evaluate的本质是选择n个点(假设f(x)的度为n)&#xff0c;计算得到其值&#xff0c;因此根据定义可以直接进行代入计算。为了加快计算的过程选取 w n w_n wn​的幂次(DFT问题即离散傅里叶变换)&#xff0c;使用FFT算法来加…...

Flutter(九)Flutter动画和自定义组件

目录 1.动画简介2.动画实现和监听3. 自定义路由切换动画4. Hero动画5.交织动画6.动画切换7.Flutter预置的动画过渡组件自定义组件1.简介2.组合组件3.CustomPaint 和 RenderObject 1.动画简介 Animation、Curve、Controller、Tween这四个角色&#xff0c;它们一起配合来完成一个…...

【python】可视化

柱状图 matplotlib之pyplot模块之柱状图&#xff08;bar()&#xff1a;基础参数、外观参数&#xff09;_plt.bar_mighty13的博客-CSDN博客 bar()的基础参数如下&#xff1a; x&#xff1a;柱子在x轴上的坐标。浮点数或类数组结构。注意x可以为字符串数组&#xff01; height&…...

C++继承多接口,调用虚函数跳转到错误接口的虚函数的奇怪问题

问题重现 定义了两个接口IA IB class IA{public:virtual void funA() = 0; }; class IB{public:virtual void funB() = 0; }...

C++:日期类

学习目标&#xff1a; 加深对四个默认构造函数的理解&#xff1a; 1.构造函数 2.析构函数 3.拷贝构造 4.运算符重载 实现功能 1.比较日期的大小 2.日期-天数 3.前/后置&#xff0c;-- 这里基本会使用运算符重载 定义一个日期类 class Date { public://1.全缺省参数的构造函数Da…...

c++ 学习之 构造函数的使用

上代码 class person { public:person(){cout << " person 的无参默认构造函数 " << endl;}person(int age){cout << " person 的有参默认构造函数 " << endl;m_age age;}person(const person& other){cout << "…...

算法通关村15关 | 超大规模数据场景常见问题

1.用4KB内存寻找重复元素 题目&#xff1a;给定一个数组&#xff0c;包含从1到N的整数&#xff0c;N最大为32000&#xff0c;数组可能还有重复值&#xff0c;且N的取值不定&#xff0c;若只有4KB的内存可用&#xff0c;该如何打印数组中所有重复元素。 分析&#xff1a; 本身是…...

qemu编译与使用

文章目录 1、安装依赖2、下载qemu源码3、编译4、运行5、qemu参数 qemu 是一个硬件虚拟化程序&#xff08;hypervisor that performs hardware virtualization&#xff09;&#xff0c;与传统的 VMware / VirtualBox 之类的虚拟机不同&#xff0c;它可以通过 binary translation…...

bazel远程构建(Remote Execution)

原理 既然 ActionResult 可以被不同的 Bazel 任务共享&#xff0c;说明 ActionResult 和 Action 在哪里执行并没有关系。因此&#xff0c;Bazel 在构建时&#xff0c;可以把 Action 发送给另一台服务器执行&#xff0c;对方执行完&#xff0c;向 CAS 上传 ActionResult&#x…...

uniapp 微信小程序仿抖音评论区功能,支持展开收起

最近需要写一个评论区功能&#xff0c;所以打算仿照抖音做一个评论功能&#xff0c;支持展开和收起&#xff0c; 首先我们需要对功能做一个拆解&#xff0c;评论区功能&#xff0c;两个模块&#xff0c;一个是发表评论模块&#xff0c;一个是评论展示区。接下来对这两个模块进行…...

js:创建一个基于vite 的React项目

相关文档 Vite 官方中文文档React 中文文档React RouterRedux 中文文档Ant Design 5.0Awesome React 创建vite react项目 pnpm create vite react-app --template react# 根据提示&#xff0c;执行命令 cd react-app pnpm install pnpm run dev项目结构 $ tree -L 1 . ├─…...

论文阅读_医疗知识图谱_GraphCare

英文名称: GraphCare: Enhancing Healthcare Predictions with Open-World Personalized Knowledge Graphs 中文名称: GraphCare&#xff1a;通过开放世界的个性化知识图增强医疗保健预测 文章: http://arxiv.org/abs/2305.12788 代码: https://github.com/pat-jj/GraphCare 作…...

Android 蓝牙开发( 四 )

前言 上一篇文章给大家分享了Kotlin版的Android蓝牙的基础知识和基础用法&#xff0c;不过上一篇都是一些零散碎片化的程序&#xff0c;&#xff0c;这一篇给大家分享Android蓝牙开发实战项目KotlinCompose的初步使用 效果演示 : Android Compose 蓝牙开发 Android蓝牙实战开发…...

涂鸦智能携手亚马逊云科技 共建“联合安全实验室” 为IoT发展护航

2023年8月31日&#xff0c;全球化IoT开发者平台涂鸦智能&#xff08;NYSE: TUYA&#xff0c;HKEX: 2391&#xff09;在“2023亚马逊云科技re:Inforce中国站”大会宣布与全球领先的云计算公司亚马逊云科技共同成立“联合安全实验室”&#xff0c;旨在加强IoT行业的安全合规能力与…...

Oracle21C--Windows卸载与安装

卸载方法&#xff1a; &#xff08;1&#xff09;WinR&#xff0c;输入services.msc,打开服务&#xff0c;把Oracle相关的服务全部停止运行&#xff08;重要&#xff09; &#xff08;2&#xff09;WinR&#xff0c;输入regedit&#xff0c;打开注册表&#xff0c;删除Oracle开…...

关于 MySQL、PostgresSQL、Mariadb 数据库2038千年虫问题

MySQL 测试时间&#xff1a;2023-8 启动MySQL服务后&#xff0c;将系统时间调制2038年01月19日03时14分07秒之后的日期&#xff0c;发现MySQL服务自动停止。 根据最新的MySQL源码&#xff08;mysql-8.1.0&#xff09;分析&#xff0c;sql/sql_parse.cc中依然存在2038年千年虫…...

Linux - Docker 安装使用 常用命令 教程

Docker 官方文档地址: Get Started | Docker 中文参考手册: https://docker_practice.gitee.io/zh-cn/ 1.什么是 Docker 1.1 官方定义 最新官网首页 # 1.官方介绍 - We have a complete container solution for you - no matter who you are and where you are on your contain…...

手游刚开服就被攻击怎么办?如何防御DDoS?

开服初期是手游最脆弱的阶段&#xff0c;极易成为DDoS攻击的目标。一旦遭遇攻击&#xff0c;可能导致服务器瘫痪、玩家流失&#xff0c;甚至造成巨大经济损失。本文为开发者提供一套简洁有效的应急与防御方案&#xff0c;帮助快速应对并构建长期防护体系。 一、遭遇攻击的紧急应…...

模型参数、模型存储精度、参数与显存

模型参数量衡量单位 M&#xff1a;百万&#xff08;Million&#xff09; B&#xff1a;十亿&#xff08;Billion&#xff09; 1 B 1000 M 1B 1000M 1B1000M 参数存储精度 模型参数是固定的&#xff0c;但是一个参数所表示多少字节不一定&#xff0c;需要看这个参数以什么…...

【Java学习笔记】Arrays类

Arrays 类 1. 导入包&#xff1a;import java.util.Arrays 2. 常用方法一览表 方法描述Arrays.toString()返回数组的字符串形式Arrays.sort()排序&#xff08;自然排序和定制排序&#xff09;Arrays.binarySearch()通过二分搜索法进行查找&#xff08;前提&#xff1a;数组是…...

在四层代理中还原真实客户端ngx_stream_realip_module

一、模块原理与价值 PROXY Protocol 回溯 第三方负载均衡&#xff08;如 HAProxy、AWS NLB、阿里 SLB&#xff09;发起上游连接时&#xff0c;将真实客户端 IP/Port 写入 PROXY Protocol v1/v2 头。Stream 层接收到头部后&#xff0c;ngx_stream_realip_module 从中提取原始信息…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

C++.OpenGL (10/64)基础光照(Basic Lighting)

基础光照(Basic Lighting) 冯氏光照模型(Phong Lighting Model) #mermaid-svg-GLdskXwWINxNGHso {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-GLdskXwWINxNGHso .error-icon{fill:#552222;}#mermaid-svg-GLd…...

OPENCV形态学基础之二腐蚀

一.腐蚀的原理 (图1) 数学表达式&#xff1a;dst(x,y) erode(src(x,y)) min(x,y)src(xx,yy) 腐蚀也是图像形态学的基本功能之一&#xff0c;腐蚀跟膨胀属于反向操作&#xff0c;膨胀是把图像图像变大&#xff0c;而腐蚀就是把图像变小。腐蚀后的图像变小变暗淡。 腐蚀…...

动态 Web 开发技术入门篇

一、HTTP 协议核心 1.1 HTTP 基础 协议全称 &#xff1a;HyperText Transfer Protocol&#xff08;超文本传输协议&#xff09; 默认端口 &#xff1a;HTTP 使用 80 端口&#xff0c;HTTPS 使用 443 端口。 请求方法 &#xff1a; GET &#xff1a;用于获取资源&#xff0c;…...

省略号和可变参数模板

本文主要介绍如何展开可变参数的参数包 1.C语言的va_list展开可变参数 #include <iostream> #include <cstdarg>void printNumbers(int count, ...) {// 声明va_list类型的变量va_list args;// 使用va_start将可变参数写入变量argsva_start(args, count);for (in…...

Vite中定义@软链接

在webpack中可以直接通过符号表示src路径&#xff0c;但是vite中默认不可以。 如何实现&#xff1a; vite中提供了resolve.alias&#xff1a;通过别名在指向一个具体的路径 在vite.config.js中 import { join } from pathexport default defineConfig({plugins: [vue()],//…...