Hology
Hology
Hology
  • 👋Welcome to Hology Docs
  • Getting started
    • Introduction to Hology
    • The first steps
    • Editor basics
      • Flying in scenes
      • Placing objects
      • Select objects
      • Transform
      • Grouping objects
      • Duplicate
    • Starter project - Third person shooter
  • Tutorials
    • Rolling ball - Gameplay programming
    • Character movement programming
    • Character AI behavior
  • Release
    • Distribution
      • Discord Activities
      • Facebook Instant Games
      • Upload to Itch.io
      • Host with GitHub Pages
      • Publishing to Steam
      • iOS and Android
  • Assets
    • 3D Models
      • Custom collision shapes
      • Material slots
    • Materials
    • Textures
    • Prefabs
  • Gameplay
    • Actors
      • Creating actor classes
      • Actor parameters
      • Actor components
      • Actor lifecycle
      • Spawning actors
      • Moving actors
    • Services
      • Load assets
    • Player input
    • Collision detection
    • Physics
      • Physics body types
      • Applying forces
      • Ray casting
    • Trigger volumes
    • Character movement
    • Pointer events
    • Animation
      • Animation system
      • Character Animation
      • Animation State Machine
    • Sound
      • Audio parameter
    • World
    • Navigation
  • Shaders
    • Introduction to shaders
    • Creating shaders
    • Shader parameters
    • Typescript shaders
      • Types
      • Math functions
      • Attributes
      • Varying
      • Uniforms
      • Textures
      • Arrays
      • Select
      • Lighting
    • Painted materials
    • Water shader tutorial
  • Level design
    • Landscape sculpting
    • Landscape painting
    • Grass
  • User Interfaces
    • Creating user interfaces
    • Using React
    • VR
  • Visual Effects
    • Introduction to VFX
    • VFX Assets
  • Integrations
    • Arcweave
Powered by GitBook
On this page
  • Creating a new actor class
  • Creating an actor class from the editor
  • Hot reloading
  1. Gameplay
  2. Actors

Creating actor classes

Actors are implemented as classes in you project's code.

Creating a new actor class

The actor class is defined in a .ts file in your code. A convention is to place these in the folder src/actors. In the code below, we have a basic starting point for an actor.


// src/actors/example-actor.ts
import { Actor, BaseActor } from "@hology/core/gameplay";

@Actor()
class ExampleActor extends BaseActor {

  onInit() {
    
  }
  
  onBeginPlay() {
  
  }
  
  onEndPlay() {
  
  }
  
  onUpdate(deltaTime: number) {
    
  }
  
}

export default ExampleActor 

This is all you need if you only intend to spawn the actor through you game.

Making actors available in the Hology Editor

In addition to defining your class, you need to export it. This is done in the index.ts file. If this is not done, the editor will not be able to find your actor class.


// src/actors/index.ts
import ExampleActor from "./example-actor";

export default {
  ExampleActor,
  // add other actors here
}

Creating an actor class from the editor

An easier way to create the starting code for an actor is to do it through the editor. It will generate code for you with a given actor class name. Click the Add new button in the asset browser and select Actor class.

Hot reloading

The editor will monitor your code to find any new actor classes that can be instantiated as actor instance in your scenes. Also, if the actor code changes, actors in in your scene will be refreshed to reflect any visual changes.

PreviousActorsNextActor parameters

Last updated 1 year ago