Skip to content

Spawning entities (server realm)

The server-side component spawns entities with re.EntitySystem. Every client in range spawns them in its game, and the callback receives the new entity's id, or null when the server couldn't create it:

// A character, simulated by the owning client
re.EntitySystem.Create(
    new TDBID("Character.Judy"),
    re.EntityType.Humanoid,
    owner,
    position,
    orientation,
    entity => Console.WriteLine($"Spawned {entity}"),
    gender: new CName("Female")
);

// A vehicle
re.EntitySystem.Create(new TDBID("Vehicle.v_standard2_archer_hella_player"), re.EntityType.Vehicle,
    owner, position, orientation, entity => { });

// A static prop from an entity template
re.EntitySystem.CreateProp(new ResRef(@"base\gameplay\devices\street_signs\race_checkpoint\race_checkpoint.ent"),
    position, orientation, entity => { });

re.EntitySystem.Delete(entity);
  • Create takes re.EntityType.Humanoid, re.EntityType.Vehicle or re.EntityType.Prop. Any other type returns false
  • Humanoids need a gender, "Male" or "Female" exactly as written. Without one Create returns false and logs the reason on the server
  • The record has to match the type: a Character record for humanoids, a Vehicle record for vehicles, a Prop record for props. Clients log a record that doesn't match, or a record from a bundle that isn't started, and don't spawn that entity
  • appearance picks the record's appearance, default when left out
  • The callback runs once the server has created the entity. That doesn't mean every client has it in their game yet

Props

A prop is a static object, a radio, a sign or a crate. It is owned by the server, so no client simulates it: clients only receive its position, orientation and appearance. Move it from script with re.ecs.TransformComponent.SetPosition.

  • CreateProp takes the path of an entity template (.ent) as a ResRef. Upper and lower case and either slash direction work. A default ResRef returns false
  • A prop can also come from a Prop record with Create and re.EntityType.Prop. The owner is ignored, props always belong to the server
  • Templates that are characters, vehicles, devices or loot are refused by clients, spawn those with their own types instead
  • A path or record that doesn't exist is logged on clients and spawns nothing. A joining client keeps trying for up to 30 seconds while the world around the prop streams in