Unreal Engine 4 C++ 插件介绍

Unreal Engine 4 C++ 插件介绍

好记性不如烂笔头啊,还是记录一下!


1.创建插件

创建插件的步骤很简单,但是很容易出错:

  1. 关闭项目,在项目目录下创建Plugins文件夹
  2. 拷贝一个空白插件(BlankPlugin)到Plugins文件夹下(BlankPlugin位于路径Engine/Plugins/Developer/BlankPlugin)
  3. 把文件夹,文件名,文件内容里面所有的 BlankPlugin 替换为你的插件名字
  4. 重新生成项目
  5. 重新编译项目

会发现你的项目中已经自动检测出了插件:

项目示例

其中<插件名称>.uplugin为插件的描述文件:

{
    "FileVersion" : 3,
    "Version" : 1,
    "VersionName" : "1.0",
    "FriendlyName" : "MyTestPlugin",
    "Description" : "Test Plugin Develop",
    "Category" : "Tests",
    "CreatedBy" : "Colocasia",
    "CreatedByURL" : "",
    "DocsURL" : "",
    "MarketplaceURL" : "",
    "SupportURL" : "",
    "EnabledByDefault" : true,
    "CanContainContent" : false,
    "IsBetaVersion" : false,
    "Installed" : false,
    "Modules" :
    [
        {
            "Name" : "MyTestPlugin",
            "Type" : "Developer",
            "LoadingPhase" : "Default"
        }
    ]
}

描述文件不能乱改,否则会导致加载失败,需要修改可以参考官方文档:描述器文件格式

插件中也有项目的配置文件,<插件名称>.Build.cs

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

namespace UnrealBuildTool.Rules
{
    public class MyTestPlugin : ModuleRules
    {
        public MyTestPlugin(TargetInfo Target)
        {
            PublicIncludePaths.AddRange(
                new string[] {
                    // "MyTestPlugin/Public"
                    // ... add public include paths required here ...
                }
            );

            PrivateIncludePaths.AddRange(
                new string[] {
                    "MyTestPlugin/Private"
                    // ... add other private include paths required here ...
                }
            );

            PublicDependencyModuleNames.AddRange(
                new string[]
                {
                    "Core",
                    "CoreUObject"
                    // ... add other public dependencies that you statically link with here ...
                }
            );

            PrivateDependencyModuleNames.AddRange(
                new string[]
                {
                    // ... add private dependencies that you statically link with here ...
                }
            );

            DynamicallyLoadedModuleNames.AddRange(
                new string[]
                {
                    // ... add any modules that your module loads dynamically here ...
                }
            );
        }
    }
}

然后配置完后就可以像引擎编写模块一样,愉快的编写代码了。


2.C++静态链接插件

在说此方法之前,先引用下官网的说明,不是很推荐用这种方法:

为了使插件真正可插拔,我们通常不鼓励为插件添加依赖关系。

但是如果一个游戏各个系统都是一个个插件,或者有人发布了很好用的代码类的工具插件,就可以用下面的方式进行静态链接。(静态链接后如果找不到插件编译会报错)

在你需要依赖的模块的<模块名称>.Build.cs中加入下列代码:

PrivateDependencyModuleNames.AddRange(
    new string[] {
        "MyTestPlugin"
    }
);

PrivateIncludePathModuleNames.AddRange(
    new string[] {
        "MyTestPlugin"
    }
);

这样就可以访问插件中的接口了,不过这里有个大坑:

插件中的要让其他模块访问的接口要符合模块API的标准

这个问题曾经困扰了我很久:

/**
 * Example of declaring a UObject in a plugin module
 */
UCLASS()
class MYTESTPLUGIN_API UMyTestObject : public UObject
{
    GENERATED_UCLASS_BODY()
};

比如这个例子中:你想UMyTestObject被游戏中的模块创建,必须加入MYTESTPLUGIN_API这个标记,否则会报无法找到定义的LINK2019错误。加入的标记符合<插件名称>_API,注意插件名称必须为大写。

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unreal Engine 4 Scripting with C++ Cookbook 2016 | ISBN-10: 1785885545 | 431 pages | PDF | 7 MB Key Features A straightforward and easy-to-follow format A selection of the most important tasks and problems Carefully organized instructions to solve problems efficiently Clear explanations of what you did Solutions that can be applied to solve real-world problems Book Description Unreal Engine 4 (UE4) is a complete suite of game development tools made by game developers, for game developers. With more than 100 practical recipes, this book is a guide showcasing techniques to use the power of C++ scripting while developing games with UE4. It will start with adding and editing C++ classes from within the Unreal Editor. It will delve into one of Unreal's primary strengths, the ability for designers to customize programmer-developed actors and components. It will help you understand the benefits of when and how to use C++ as the scripting tool. With a blend of task-oriented recipes, this book will provide actionable information about scripting games with UE4, and manipulating the game and the development environment using C++. Towards the end of the book, you will be empowered to become a top-notch developer with Unreal Engine 4 using C++ as the scripting language. What you will learn Build function libraries (Blueprints) containing reusable code to reduce upkeep Move low-level functions from Blueprint into C++ to improve performance Abstract away complex implementation details to simplify designer workflows Incorporate existing libraries into your game to add extra functionality such as hardware integration Implement AI tasks and behaviors in Blueprints and C++ Generate data to control the appearance and content of UI elements

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值