-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial Update Manager
In CodeOptPro you can use another powerful feature that allows you to use custom update to update your script, that 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 issues as one script is handling the call for processes. There are two types of custom update classes in CodeOptPro they are COP_UpdateManager and COP_UpdateManagerGlobalHelper. Each of these custom update classes have 2 more types which are process_manager_local and physics_process_manager_local for the COP_UpdateManager. And process_manager_global and physics_process_manager_global for the COP_UpdateManagerGlobalHelper. The main logic between all of them are same but the only difference is that the local ones needs to be referenced by dragging and dropping the node object containing the script while the global ones are referenced by giving the resource reference. Below I will explain how to use the custom update manager.
The first task you need to do is to add at least one update manager in the scene. This could be added any where but it is best to add all update managers under one Node called UpdateManagers so that it remains organized and easy to debug. So create a new Node called UpdateManager1 and add any of the update manager scripts called physics_process_manager_global, process_manager_global, physics_process_manager_local or process_manager_local. Now let me explain the properties of the update manager.
- a. Helper (Only available in the global types) - This the cop_update_manager_global_helper resource that helps to keep the code decoupled. The update objects will use this reference to interact with the update manager. This property is only available for the global types. There is already a cop_update_manager_global_helper resource created called default_update_manager. You can use this as well for your project if you want to.
- b. Objects - This is an array which will contain all the update objects related to this update manager. These objects will share one _physics_process(delta) or _process(delta) method from the update manager. You can manually add the update objects here but that is NOT recommended. Instead we shall use the Auto Setup plugin to add update objects to update managers automatically. Will talk about how to create an update object and using Auto Setup plugin later below.
- c. Num Update - This value handles how many objects should be updated per frame. For example if this value is set to 5 then 5 objects will be update in one frame cycle. If there are too many update objects that needs to be updated then increasing this value should make the update process much better but that depends on your scripts and their logic.
- d. Is Set Num Update - If set true then will automatically set the Num Update value to the number of objects added to the update manager. If null or false then the Num Update value will be used and auto setup for Num Update won't work. For example if there are 5 objects added and the Num Update value is 1 and Is Set Num Update value is true then the actual num update value will be 5. Note: This value can remain null as null is taken as a false flag here.
The second step is to create an update object. It is very easy to create an update object. If you haven't copied the folder script_templates to the main folder res:// then do that now as we will needed the update object template to create our scripts. Once that is done then create a new script. In the Inherits: field select Node. Then in the Template: field either select Cop Update Object Global Tepmlate, if you have added the global update manager, or select Cop Update Object Local Template, if you have added the local update manager. Name the script anything you want and then press Create button. I have commented the script with much details but I will explain what each of these properties and functions does.
- Tutorial Bar
- Tutorial Debug
- Tutorial Instantiate Object
- Tutorial Pool
- Tutorial Timer
- Tutorial Update Manager
- Tutorial Variable Creator
- Bars
- Debugs
- Maths
- Pools
- Resources
- Fixed Vars
- Managers
- Observers
- Vars
- Script Templates
- Timers
- Updates