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);
Createtakesre.EntityType.Humanoid,re.EntityType.Vehicleorre.EntityType.Prop. Any other type returnsfalse- Humanoids need a gender,
"Male"or"Female"exactly as written. Without oneCreatereturnsfalseand logs the reason on the server - The record has to match the type: a
Characterrecord for humanoids, aVehiclerecord for vehicles, aProprecord 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 appearancepicks the record's appearance,defaultwhen 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.
CreateProptakes the path of an entity template (.ent) as aResRef. Upper and lower case and either slash direction work. A defaultResRefreturnsfalse- A prop can also come from a
Proprecord withCreateandre.EntityType.Prop. Theowneris 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