Home | Features | Roadmap | Learn | Documentation | ||
Latest version: Tramway SDK 0.0.9 Github Quick links Home Get Started |
EntityEntities are one of the main concepts of the framework. An entity is a thing. Anything. A part of the level geometry, an interactable object, a pickup or an NPC. Entities are also the things that receive messages and the things that you place down in the level editor. Most of your entities will probably be placed in WorldCells, which are the basic level and streaming units of your virtual world. Re-usable parts of the entity logic are usually placed into EntityComponents and entities are then assembled out of them. Key conceptsIDEach entity gets its own unique ID number. You can assign an ID number to an entity, or the framework can generate one for you. No two entities can have the same ID number, since then the framework will assume that one of the entitie is a copy and will yeet it. NameEntities can be given names, but unlike an ID, these are optional. This is also how you will refer to specific entities most of the time. TypeEach entity has a type. It determines its behavior and what kinds of properties it has. PropertiesEach entity has properties. These can be numbers, strings, vectors or other kinds of types. An entity's properties can be edited in the level editor. They are also called parameters, fields and entity data. Mostly because I keep forgetting how this concept is called. Location/RotationEach entity gets a rotation and a location. This transform is used to determine in which WorldCell the entity is located in and when to load and unload it Loading/UnloadingWhen an entity is constructed, either through code or from a record in a WorldCell file on disk, it starts out unloaded and has no EntityComponents attached to it. It just sits there, doing nothing. When an entity is loaded, either when its WorldCell is loaded or on some other event, it will construct its EntityComponents and pass its properties to them. When unloaded again, it will pack up and yeet all of its EntityComponents. This saves on computational resources – it allows the framework to process only a small part of all of the entities at the same time. Programming in C++
If you want to create your own entity type, a good place to start would be by copying the Marker entity. The other way would be to create a subclass of the Entity class and then implement all of its virtual methods. If you want the Entity to be loadable from a level file, you also need to add an entity type registration static method. Additionally, you could add the type to your project's entity definition file, so that the level editor and other utilities can process your entity type.
To interact with an entity, you first need to get a pointer to it. You can
get the pointer by using the
Entity* entity1 = Entity::Find("bingus");
It is also possible to query its transform and to change it.
vec3 position = entity->GetLocation();
There are a lot of other methods for the Entity class. Check the API documentation for them. Scripting in LuaThe Lua API is basically the same as the C++ API.
local bingus = tram.entity.Find("bingus")
|
|
|