Coder Social home page Coder Social logo

unreal.hx's Introduction

Unreal.hx

Unreal.hx is a plugin for Unreal Engine 4 that allows you to write code in the Haxe programming language. Haxe is a modern, high-level, type-safe programming language that offers high performance critical for game development.

Main Features

  • Haxe compiles directly to C++, for high runtime performance.
  • Full access to the entire Unreal C++ API - including delegates and lambdas.
  • Full support for UCLASS creation, subclassing, and Blueprints.

Haxe Features

  • Familiar C/Java-style syntax.
  • Memory management via garbage collection.
  • Strict type safety, with a powerful type inference engine.
  • Many modern features such as lambdas/closures, generics, abstract data types (GADT's), reflection, metadata, and a powerful macro system for language extension.

Setup

  • Make sure you've got a working haxe installation, and have the hxcpp and hxcs haxelibs installed
  • Clone this library or add it as a submodule to your Unreal project in the Plugins/UE4Haxe directory
  • Port your main Build.cs module to Build.hx and make sure it extends HaxeModuleRules
  • On the Plugins/UE4Haxe directory, run haxe init-plugin.hxml to make sure your Build.hx file was built
  • A new directory, Haxe, will be created at the root of your project. Add any class to be compiled to Haxe/Static, and you may add new compiler arguments to the arguments.hxml file
  • For the latest master, you will need Haxe 3.3 and Unreal 4.11

Examples

package mygame;
import unreal.*;

@:uclass
class AMyActor extends AActor {
  // make a property that is editable in the editor.
  @:uproperty(EditDefaultsOnly, Category=Inventory)
  var items:TArray<AActor>;
  
  // make a function that is callable from C++/Blueprints
  @:ufunction(BlueprintCallable, Category=Inventory)
  public function addToInventory(item:AActor) {
    items.push(item);
  }
  
  // override native C++ function
  override function Tick(deltaTime:Float32) : Void {
    super.Tick(deltaTime); // call super functions
    trace('Hello, World!'); // all traces are redirected to Unreal's Log
    trace('Warning', 'Some Warning'); // and it supports Warning, Error and Fatal as well
  }
  
  // tell Unreal to call our Tick function
  public function new(wrapped) {
    super(wrapped);
    this.PrimaryActorTick.bCanEverTick = true;
  }
}
package mygame;
import unreal.*;

@:uclass
class AMyGameMode extends AGameMode {
  @:uproperty(BlueprintReadWrite)
  public var playerName:FString;
  
  @:ufunction(BlueprintCallable)
  public function makeExternalRequest(data:String) {
    // use Unreal C++ API to make an HTTP Request
    var httpRequest = FHttpModule.Get().CreateRequest();
    httpRequest.SetVerb("GET");
    httpRequest.SetHeader("Content-Type", "application/json");
    httpRequest.SetURL("www.mygame.com/players");
    
    // use Haxe JSON library to encode data.
    var json = {
      name: this.playerName,
      playerData: data,
    };
    httpRequest.SetContentAsString(haxe.Json.stringify(json));
    
    // Receive a callback when the response is received.
    httpRequest.OnProcessRequestComplete.BindLambda(function (request, response, success) {
      trace('response received: ${response.GetContentAsString()}');
    });
    
    httpRequest.ProcessRequest();
  }
}

For a complete example project, check out https://github.com/waneck/HaxePlatformerGame , which is a port of Unreal's Platformer Game demo to Haxe 3.3/Unreal 4.11

More information is available on the Wiki

unreal.hx's People

Contributors

waneck avatar dogles avatar djlennon avatar paulproletariat avatar chetrippo avatar prolenorm avatar hhcrhinehart avatar danbrakeley avatar leereilly avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.