当前位置:网站首页>ue4 物品随机生成
ue4 物品随机生成
2022-07-24 05:22:00 【真的没事鸭】
这个只是简单的讲解一下物品生成时的概率问题,可以根据自己的需要在此基础上拓展
创建两个结构体蓝图

分别表示物体生成的位置和要生成的物体模型
在ST_Location里面创建一个Vector变量

在ST_Item里面创建两个变量

分别是当前物品生成的概率和这个物品的Actor引用
然后根据这两个结构体蓝图,创建两个数据表格


在DT_Location里面添加五行
然后我们要给这五行分别设置位置
在地图中拖出五个立方体,把这个五个立方体的位置分别设置给DT_Location


位置可以直接复制粘贴过去


然后把拉出的五个立方体删除
创建四个actor蓝图(添加StaticMesh,然后把Mesh修改成自己想要的模型),模型随便,不一样即可
这里为了演示用了蓝图,但是如果你要生成物品很多的话就会很麻烦,解决办法就是创建一个父类蓝图通过物品ID来修改蓝图的StaticMesh

然后设置一下DT_Item

BluePrint分别设置成刚才创建的四个物品蓝图,概率分别是10,20,30,40
然后创建一个GameMod

在世界大纲里面把游戏模式修改为MyGameMod

我们在GameMod里面实现生成物品的操作
创建一个函数,命名为GenerationItem,遍历之前创建的位置数据表格

每获取一个位置就随机生成一个物品,再创建一个函数命名为RandomItem,这个函数用来随机产生一个物品的类引用
在这个函数创建一个局部变量Arr,类型是Actor引用数组

原理就是在Arr数组中加入物品对应概率的数量,然后再打乱随机出一个物品

然后回到GenerationItem函数中调用这个函数生成物品

在事件图标的begin play后面调用GenerationItem即可

运行生成物品如下

有什么不对的地方欢迎评论区指正
有什么问题可以在评论区问我
边栏推荐
- [deep learning] handwritten neural network model preservation
- JUC并发编程基础(1)--相关基础概念
- PDF Text merge
- Use QT to connect to MySQL and create table numbers, write data, and delete data
- Common methods of array
- [raspberry pie 4B] VII. Summary of remote login methods for raspberry pie xshell, putty, vncserver, xrdp
- Accessing a one-dimensional array with a pointer
- 餐饮数据统计分析---泰迪云课程大作业
- day4-jvm
- Accurate calculation of time delay detailed explanation of VxWorks timestamp
猜你喜欢

HoloLens 2 开发101:创建首个HoloLens 2应用程序
![[MYCAT] MYCAT configuration file](/img/53/63a633d3ae917e3754f9f7f5c6567f.png)
[MYCAT] MYCAT configuration file

Openpose2d转换3d姿态识别
![[USB host] stm32h7 cubemx porting USB host with FreeRTOS to read USB disk, usbh_ Process_ The OS is stuck. There is a value of 0xa5a5a5](/img/be/b7723920f0e81e8699bb26dd1c0fe5.png)
[USB host] stm32h7 cubemx porting USB host with FreeRTOS to read USB disk, usbh_ Process_ The OS is stuck. There is a value of 0xa5a5a5

Raspberry pie is of great use. Use the campus network to build a campus local website

Day-7 JVM end

Machine learning (Zhou Zhihua) Chapter 4 notes on learning experience of decision tree

JUC并发编程基础(9)--线程池

Qt新手入门级 计算器加、减、乘、除、应用
![[FatFs] migrate FatFs manually and transfer SRAM virtual USB flash disk](/img/fb/5f3d17f1f3d6e4979ece5126e2925e.png)
[FatFs] migrate FatFs manually and transfer SRAM virtual USB flash disk
随机推荐
用指针访问二维数组
Introduction to QT new project
Pytorch single machine multi card distributed training
JUC concurrent programming foundation (9) -- thread pool
JDBC进阶—— 师承尚硅谷(DAO)
Iotp2pgate two IOT devices point-to-point communication fast implementation scheme
Accessing a one-dimensional array with a pointer
How to solve the problem of large distribution gap between training set and test set
Openpose2d转换3d姿态识别
Foundation of JUC concurrent programming (1) -- related basic concepts
Search of two-dimensional array of "sword finger offer" C language version
Calculation steps of principal component analysis
JDBC elementary learning ------ (learning from Shang Silicon Valley)
[USB host] stm32h7 cubemx porting USB host with FreeRTOS to read USB disk, usbh_ Process_ The OS is stuck. There is a value of 0xa5a5a5
HoloLens2开发:使用MRTK并且模拟眼动追踪
QT char to qstring hexadecimal and char to hexadecimal integer
[MYCAT] Introduction to MYCAT
Day3 jvm+ sorting summary
Machine learning (zhouzhihua) Chapter 2 model selection and evaluation notes learning experience
Traditional K-means implementation