博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UE4里的全局变量,全局函数
阅读量:6626 次
发布时间:2019-06-25

本文共 2371 字,大约阅读时间需要 7 分钟。

hot3.png

Create The CPP Base Class
SolusDataSingleton.h

UCLASS(Blueprintable, BlueprintType)class USolusDataSingleton : public UObject{	GENERATED_BODY()public:        USolusDataSingleton(const FObjectInitializer& ObjectInitializer); 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Solus Data Singleton")	TArray
SolusTreeBlueprints; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Solus Data Singleton") UTexture2D* SolusT2D; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Solus Data Singleton") FVector SolusEssentialVector; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Solus Data Singleton") FString SolusCoreFilePath;};

SolusDataSingleton.cpp

#include "Solus.h"#include "SolusDataSingleton.h"USolusDataSingleton::USolusDataSingleton(const FObjectInitializer& ObjectInitializer)	: Super(ObjectInitializer){ 	SolusCoreFilePath = "E:/Solus"; 	SolusEssentialVector = FVector(9000,0,0);}

 

Create The BP_ClassXXX of the CPP Class

Project Settings->Engine->General, 将Game Singleton Class设置为BP_ClassXXX

 

Easily Set Default Values Any Time!

Function Library To Access Anywhere in BP

SolusDataSingletonLibrary.h

#pragma once //Data Singleton Class#include "SolusDataSingleton.h" #include "SolusDataSingletonLibrary.generated.h" //note about UBlueprintFunctionLibrary// This class is a base class for any function libraries exposed to blueprints.// Methods in subclasses are expected to be static, and no methods should be added to the base class. UCLASS()class SOLUS_API USolusDataSingletonLibrary : public UBlueprintFunctionLibrary{	GENERATED_BODY()public:	USolusDataSingletonLibrary(const FObjectInitializer& ObjectInitializer); 	UFUNCTION(BlueprintPure,   Category="Solus Data Singleton")	static USolusDataSingleton* GetSolusData(bool& IsValid); };

SolusDataSingletonLibrary.cpp

#include "Solus.h"#include "SolusDataSingletonLibrary.h"//// USolusDataSingletonLibrary USolusDataSingletonLibrary::USolusDataSingletonLibrary(const FObjectInitializer& ObjectInitializer)	: Super(ObjectInitializer){  } USolusDataSingleton* USolusDataSingletonLibrary::GetSolusData(bool& IsValid){	IsValid = false;	USolusDataSingleton* DataInstance = Cast
(GEngine->GameSingleton); if(!DataInstance) return NULL; if(!DataInstance->IsValidLowLevel()) return NULL; IsValid = true; return DataInstance;}

 

转载于:https://my.oschina.net/robslove/blog/876648

你可能感兴趣的文章
前端面试回忆录 - 滴滴篇 - 凉面
查看>>
jxl导入Excel 切割List 并使用MyBatis批量插入数据库
查看>>
小程序开发总结
查看>>
Tomcat监听器设计思路
查看>>
管理ORACLE实例
查看>>
Confluence 6 MySQL 数据库设置准备
查看>>
Ruby 中 0/0.0 = NaN
查看>>
JEESNS数据库表设计结构
查看>>
JavaScript学习笔记:判断变量是否为undefined,判断变量和函数是否声明
查看>>
局域网访问Apache服务器
查看>>
JavaScript 闭包
查看>>
Spark算子:RDD行动Action操作(3)–aggregate、fold、lookup
查看>>
UILabel总结
查看>>
java获取当前时间前一周、前一月、前一年的时间
查看>>
话说WEB开发之页面重绘和回流
查看>>
using标识使用
查看>>
解决linux下不能上网
查看>>
nginx rewrite伪静态配置参数说明
查看>>
python学习笔记(15-18)
查看>>
Oracle 查询不区分大小写 (正则函数)
查看>>