home/ atoms/ p5live-class-instance-softcompile

Existing class instances in P5LIVE retain old methods after a softCompile; only newly-constructed instances get the updated code

When you edit a class definition in P5LIVE and trigger a softCompile (not a hardCompile), existing instances of that class continue to run their old method implementations. The updated code only takes effect for instances constructed after the recompile. This is the root cause of ‘why doesn’t my class change apply?’ confusion. To propagate the change to all instances, either re-emit (re-construct) them, or force a hardCompile (CTRL+SHIFT+ENTER). The common wrong belief is that a softCompile updates all running instances immediately.

Examples

A class Particle { update() { ... } } body is changed; the 200 existing particles in the array still run the old update() until they are replaced or the sketch restarts.

Assessment

Describe what happens to running Particle instances when you edit the class body and trigger a softCompile. What two techniques bring all instances onto the new code?

“Edit a `class Particle` and existing particles still run the old code; only newly-constructed ones get the change.”
context/ · L1-instruments/p5live/gotchas.md · chunk 1