Generate server entity||doc135512

September 20, 2022

Format

  EntityServer.Create(params, func) 

Description

Create an entity object on the server side. The creation of an entity object needs to correspond to an entity's configuration information, and an entity object's configuration information can be newly created under the component library unit of the editor.

The entity object created under the server will be automatically synchronized to the player client whose surrounding field of view can track the object for display.


Precautions

  • When using the entity object created by this function,ENTITY_ENTERTriggers are not triggered, only when the editor places entity objects on the map and creates NPCs using blueprints.
  • Be careful not to create objects when the program starts running, at least when the map is loaded, otherwise unimaginable consequences will occur

Parameters

Variable name type Description
params CreateParams Create parameters
func function Callback function with entity object as parameter


Value Returned

type Description
Entity entity object


Code Samples

Find the corresponding entity in the editor, right-click to copy its ID, plus the prefix is its configuration name (cfgName), such as 'myplugin/entity'

on the server sideglobal script, generate the server entity

local world = World.CurWorld
local defaultMap = world.defaultMap
local createParams = { cfgName = "myplugin/entity", pos = { x = 0, y = 1, z = 0 } , map = defaultMap }
local entity = EntityServer.Create(createParams)