September 20, 2022
Object scripts, as the name implies, are code scripts mounted under objects. Currently, object scripts can only be mounted under entity objects. The execution time of the object script is when the object is created in the scene, and the script can be executed through thethisto get the object instance of the mount script.
How to create an object script
In the editor, we can clickComponent Library > UnitsSelect a unit that needs to add object scripts, and select it in the unit property panel), you can add and edit server-side or client-side object scripts in the script editor. An object can add multiple object scripts, and we can classify them according to the different implementation functions.
script execution time
Server-side object script execution timing:
Since the server needs to manage all objects, the object script on the server will be executed when the object is created on the server.
Client-side object script execution timing:
For performance reasons, the client will calculate as few objects as possible that are farther away from the client (that is, objects that are beyond the client's field of view). Therefore, objects beyond the client's field of view will be destroyed from the current client, and will not be generated on the client until the object enters the client's field of view again, so the time when the client object script is executed cannot be when it is created. In fact, most of the client's object script is not used, only when the client uses EntityClient.CreateClientEntity to create a client entity object, the script on the object will be executed.