Skip to content

base_update_manager

Kamran Wali edited this page Feb 5, 2025 · 20 revisions

Class Name: COP_UpdateManager

Inherits: Node

Inherited By: physics_process_manager_local, process_manager_local

Base class for all custom update manager objects.

Description

base_update_manager is the parent/base class for all the custom update manager scripts in the tool/plugin CodeOptPro. The script is designed in a way that every new update manager type will need to extend from base_update_manager. That way it will be easier to keep the update managers organized and having common parent. This will also help in making sure that new/current update managers can be just dragged and dropped into other scripts and it will work no matter what type of an update manager is used, SOLID principles.

This script is one of the most powerful feature in CodeOptPro. It allows you to use custom update to update your script, which is the _process(delta) and _physics_process(delta). This custom update allows you to share one _process(delta) or _physics_process(delta) method with many scripts. This in turn saves lot of performance issue as one script is handling the call for processes.

This script calls the _ready() method. So if you extend this script and need to call the _ready() method then make sure to call the super class', this class, _ready() method.

Tutorials

Properties

Type Name Default Value
Array[Node] _objects
int _num_update 1
COP_FixedBoolVar _is_set_num_update
COP_FixedBoolVar _is_enabled_start
Array[Node] _remove_objects
int _pointer 0
int _index_update 0
float _time_delta 0.0
int _actual_num_update 0

Methods

Return Type Name
void add_object( Node object )
void remove_object( Node object )
void remove_object_index( int index )
bool has_object( Node object )
float get_time_delta()
float get_time_delta_process()
float get_time_delta_physics_process()
int get_size()
Node get_object_index( int index )
void set_enabled( bool is_enable )
bool is_enabled()
void _update( float delta )
void _add_object( Node object )
void _setup()
void _reset_data()
void _update_object( float delta )
void _calculate_time_delta()
void _validate_num_update()
bool _validate_is_set_num_update()
bool _is_update_manager()

Property Descriptions

Array[Node] _objects

This array contains all the objects whose update methods will be called in the update loop/frame. You can add them manually or read the Tutorials on how to automatically add update objects to the array.


int _num_update = 1

Number of objects whose update methods will be called per frame. Minimum value is 1. Example: If the value is set to 10 then 10 objects will be updated per frame.


COP_FixedBoolVar _is_set_num_update

This flag enables/disables auto number of update setup. If true then number of update will be set automatically. If null or false then the user needs to give value to the _num_update.


COP_FixedBoolVar _is_enable_start

This flag enables/disables the Update Manager at start up which is when the application starts. If null or true then it means the Update Manager will be active at start up. If false then the Update Manager will be inactive at start up. If inactive then it can be activated manually by calling the set_enabled(bool) method.


Array[Node] _remove_objects

An array containing all the objects to remove from _objects.


int _pointer = 0

A pointer that points to an object in _objects to update. Basically this pointer goes through all the objects to update them.


int _index_update = 0

The counter that updates the number of objects defined by _actual_num_update.


float _time_delta = 0.0

The delta value for this update manager. For more information check out the method _calculate_time_delta().


int _actual_num_update = 0

This is the actual number of objects that will be updated. For more information check out the method _validate_num_update().


Method Descriptions

void add_object ( Node object )

This method adds an object to the _objects array to be updated per frame. This method can also be called during run time.


void remove_object ( Node object )

This method removes an object from the _objects array.

Note: When this method is called then the update method will stop working till all remove actions are done which is when _remove_objects array is empty. If number of remove objects are small then the update pause will NOT be noticable. It is recommended NOT to call this method every frame.


void remove_object_index ( int index )

This method removes an object from the _objects array by using the given index. If you know at what index the object is at then you can use this method to remove it.

Note: When this method is called then the update method will stop working till all remove actions are done which is when _remove_objects array is empty. If number of remove objects are small then the update pause will NOT be noticable. It is recommended NOT to call this method every frame.


bool has_object ( Node object )

This method checks if the given object has already been added or exist in the array _objects array. True means the object has been added. False means the object has NOT been added.


float get_time_delta ()

This method gets the time delta value from the update manager. It is the calculated delta value for this update manager. It is recommended to use this delta value per frame if the object is being updated through this update manager.


float get_time_delta_process ()

This method gets the process' delta value from this manager. It is the calculated delta value for this update manager. It is recommended to use this delta value per frame if the object is being updated through this update manger which uses the _process method.


float get_time_delta_physics_process ()

This method gets the physics process' delta value from this manager. It is the calculated delta value for this update manager. It is recommended to use this delta value per frame if the object is being updated through this update manager which uses the _physics_process method.


int get_size ()

This method gets the number of objects added to the update manager which is to the _objects array. It basically shows the number of objects being updated.


Node get_object_index ( int index )

This method returns the index object. If the index is greater than the size of the _objects array then the method will return null.


void set_enabled ( bool is_enable )

This method enables/disables the update manager. True means to enable the update manager. False means to disable the update manager.


bool is_enabled ()

This method checks if the update manager is enabled.


void _update ( float delta )

This is the main method that handles all the update, validation and remove logic for the update manager.

Note: This method should ONLY be called by the child script in the _process() or _physics_process method.


void _add_object ( Node object )

This method adds an object to the update manager, which is the _objects array, automatically. See the Tutorials on how to add objects automatically.

Note: This method should NEVER be called from any scripts. It is ONLY called by the Automation logic.


void _setup ()

This method does all the setup for the update manager. See the Tutorials on how the setup works automatically.

Note: This method should NEVER be called from any scripts. It is ONLY called by the Automation logic. ONLY child scripts can override this method. If it is overridden by child scripts then make sure to call the super._setup() method as well to avoid any weird results.


void _reset_data ()

This method removes all the data from the update manager, which is the _objects array, automatically. See the Tutorials on how to remove objects automatically

Note: This method should NEVER be called from any scripts. It is ONLY called by the Automation logic.


void _update_object ( float delta )

This method updates the update object. It will only update the object if the object's is_active() is true.

Note: This method should NEVER be called by any scripts. It is called by the _update method ONLY.


void _calculate_time_delta ()

This method calculates the accurate time delta value, _time_delta, for this update manager. This calculation is mainly needed for sending the accurate delta, _time_delta, value to the update objects. The _time_delta value is calculated with the delta value from the methods _process or _physics_process to give the accurate delta value. This will make sure that there are no weird results when using the delta value from the update managers.


void _validate_num_update ()

This method calculates and selects the correct _actual_num_update. Basically the correct number of objects to update value is selected.


bool _validate_is_set_num_update ()

This method validates the _is_set_num_update variable.


bool _is_update_manager ()

This method always sends true as the script is update manager. This method is needed for duck typing check and SHOULD NOT be OVERRIDDEN!


Clone this wiki locally