Skip to content

Blueprint Libraries

Ruslan Mustakov edited this page May 16, 2016 · 1 revision

nimue4 provides a simple way to author "Blueprint libraries" - a set of types and procedures that are accessible from blueprints.

blueprintSection pragma

blueprintSection allows to define a set of types (structs) and procedures to be define under the same Blueprint category. Under the blueprint section, use default Nim syntax for defining object types and procedures. Example:

import ue4

blueprintSection("MyGame|Weapons"):
  type EWeaponKind = enum
    Projectile,
      ## Fires projectiles that have some travel speed
    Instant,
      ## Fires bullets that deal instant damage
    Channeled
      ## Deals damage while the fire button is being held close enough to the enemy

  type FWeaponInfo = object
    name: FText
    kind: EWeaponKind
    maxAmmo: int32
    ammoPerMagazine: int32
    reloadSpeed: float32

  proc getAvailableWeapons*(): TArray[FWeaponInfo] =
    ## Returns weapons available in the game
    result.add(FWeaponInfo(
      name: nsLocText("Weapons", "RocketLauncherName", "Rocket Launcher"),
      kind: EWeaponKind.Projectile,
      maxAmmo: 80,
      ammoPerMagazine: 8,
      reloadSpeed: 3.0
    ))
    result.add(FWeaponInfo(
      name: nsLocText("Weapons", "UziName", "Uzi"),
      kind: EWeaponKind.Instant,
      maxAmmo: 320,
      ammoPerMagazine: 32,
      reloadSpeed: 0.7
    ))

The defined function appears in the Blueprint editor as expected: Blueprint Editor

blueprint pragma

blueprint pragma is applicable to top-level procedures. It makes them callable from blueprints. For example:

import ue4

ustruct FDownloadInfo:
  var durationSecs*: float32
  var bytesDownloaded*: int32

proc getAvgBandwidth(download: FDownloadInfo): float32 {.blueprint, category: "Download", noSideEffect.} =
  ## Returns avg bandwidth for the download in bytes per second
  ## or 0.0 if the download hasn't started yet
  if download.durationSecs != 0.0:
    result = float32(download.bytesDownloaded) / download.durationSecs

Blueprint Editor

Clone this wiki locally