Writing delta time plugins

Normally an expression plugin should act like a mathematical function. You put in parameters of the current scene and objects, and out comes a new state in a predictable way. With delta time dependent plugins, this is not so. The new state is dependent not only on the current state of the scene, but also on previous states of the scene.


Even if you do not plan to write true delta time plugins, the following rules are still a good checklist for all kinds of plugins.

An example is the particle system in Cinema 4D. Every frame, each particle is moved depending on how much time has elapsed since the last frame. Thus the new state depends on the time between frames, the delta time.

When writing delta time plugins, or other kinds of plugins that behave in this way, there a few important considerations to make the plugin work under all circumstances (e.g. net rendering and MP rendering). This tutorial will present the most important requirements.


If you feel that these requirements are too complicated, then fine; your plugin will probably work if handled with care. But be sure to tell other users in a readme file that it will break when net rendering, MP rendering or whatever!


No random randomity

If you have a random number generator in your algorithm, its state must be copyable. This means that you can’t just seed it with time.time() or random.random() in every instance, because then it will give different random numbers on different machines when net rendering. You should use seed values for random generators whenever possible.

Well-defined initial state

The first frame of the scene must have a well-defined state. This is important, since Cinema 4D always pre-rolls the renderer from the first frame. The easiest way to do this is to just check in the TagData.Execute() function if the current frame is the first one, and then reset all objects to their starting positions if it is.

Use the real delta time

Do not just count on the time since your plugin was last evaluated always to be equal to 1/30th of a second, or even equal to BaseDocument.GetFps(). Always store the time of the last evaluation, and calculate the delta time yourself using (delta time) = (current time) - (previous time). The delta time might even be negative, if the user is randomly dragging the time slider.