Redundant fixed_update in the default script

Why does fixed_update show up in the default script despite physics.use_fixed_timestep being disabled by default?
It seems misleading especially to not explain it in the comments of fixed_update.
It would make most sense to either make physics.use_fixed_timestep be default enabled or to not include fixed_update in a new file unless it has been manually enabled.

It is a template file which we copy when you choose to create a new script file. We can see if we can clarify the comment a bit in the function.

1 Like

Something essential to clarify that I worry could confuse newcomers would be to specify in the default comment of fixed update that unless this specific game.project setting has been manually enabled, all code within this function is useless and will not run. I would hope Defold to be as easy to pick up and learn for new users now as it was back when I started. The ease of use and simplicity and clarity is what makes is brilliant.

As Mathias pointed out it is a template script used by the editor whenever a script component is created. It is not specifically tied to each project template and does not know of how the project is configured (fixed timestep on or off).

The template in question can be seen here:

We can be more explicit with the “Add update code here” text, but we do link back to the correct manual where we write:

fixed_update(self, dt)
Frame-rate independent update. dt contains the delta time since the last update. Useful when you wish to manipulate physics objects at regular intervals to achieve a stable physics simulation. Requires that physics.use_fixed_timestep is enabled in game.project.

4 Likes

Perhaps:

function fixed_update(self, dt)
	-- Only used if 'Use Fixed Timestep' is enabled in the Physics section of game.project
	-- Add update code here
	-- Learn more: https://defold.com/manuals/script/
	-- Remove this function if not needed
end
6 Likes

I am aware that it is a single file but considering use fixed timestep is disabled by default, it makes me think that this function should also be disabled by default. Maybe have two default script files, one with and one without, and then use whichever is based on the project settings? It seems very strange to have two conflicting defaults.

Yes, perhaps, but we do not have any support for different template files based on project settings. It would require a bit of development time from us. Adding a note like the one I suggested is a decent compromise I think.

1 Like

The other thing to possibly consider then is that if someone will go out of their way to the game.project and enable this function, I think it can be reasonably said that they know what they are doing and will probably not struggle with implementing this function. The only logical compromises I see are making physics.use_fixed_timestamp enabled by default such that no note is necessary, or making the fixed_update() function not autogenerate because the amount of projects using physics.use_fixed_timestamp is low enough that it isn’t a problem which warrants being in the default script