If you want to help us maintaining this wiki, check out our discord server: https://discord.gg/3u69jMa 

Difference between revisions of "Writing Native Code"

From SWRC Wiki
Jump to navigation Jump to search
Line 1: Line 1:
==Resources==
==Introduction==
[[Media:Headers.zip]]
Native coding in the Unreal Engine refers to code that is written in C++ instead of UnrealScript. This C++ code can be called from a script to execute tasks that are either too slow in UnrealScript (about 20 times slower than C++) or are not possible at all due to the limited features of the language.
 
Unreal Tournament headers modified to be as compatible as possible with RC.
 
[[Media:Debug.zip]]
 
Native coding example that implements the game's main loop and adds useful features like a framerate cap that can be set using a new custom console command ("SetRefreshrate") and error handling using Message boxes that show the stack trace in case of a crash. Also have a look at [[Republic Commando UCC]]


==Introduction==
==Introduction==

Revision as of 16:45, 27 January 2018

Introduction

Native coding in the Unreal Engine refers to code that is written in C++ instead of UnrealScript. This C++ code can be called from a script to execute tasks that are either too slow in UnrealScript (about 20 times slower than C++) or are not possible at all due to the limited features of the language.

Introduction

Getting Started

Code

This code assumes that the folders with the headers for Core and Engine are in the same directory as the source file

//Linking the import libraries for Core.dll and Engine.dll so that functions from these libraries can be called
#pragma comment(lib, "Core/lib/Core.lib")
#pragma comment(lib, "Engine/lib/Engine.lib")

//Including the headers for core and engine
#include "Engine/Inc/Engine.h"

//This function is going to replace appInit from UnFile.h and thus needs to have the same signature
__declspec(dllexport) void testFunc(const char* InPackage, const char* InCmdLine, FOutputDevice* InLog, FOutputDeviceError* InError,
                                    FFeedbackContext* InWarn, FConfigCache*(*ConfigFactory)(), int RequireConfig){
    const char* newCmdLine = "-windowed -log abcdefg 12345";

    InLog->Logf("Replacing command line with %s", newCmdLine);

    appInit(InPackage, newCmdLine, InLog, InError, InWarn, ConfigFactory, RequireConfig);
}

Making The Game Call Custom Code

IIDKing.PNG

Olly1.PNG

Olly2.PNG

Result.PNG