Changing beam color

I sort-of followed the “Introduction to Particles” series part “Beam Emitter” on Youtube to create a beam (the primary differences are that I don’t need a lightning-like effect, I just want a simple beam and I set two actors as “source” and “target”). This works great, the beam follows the actors as expected.

Next, I would like the color of the beam to be variable – specifically change the color depending on the length of the beam. I also want to be able to update opacity and emission.

I got the color change working using a parameter, but what happened was that the color update was no where near “real-time”. It seemed to have something like a two-second delay between updates. While in the material editor, it takes roughly two seconds for it to generate the material previews in the nodes. I don’t know if it’s a coincidence, but I’m going to guess that the two are related.

Given the “Beam Emitter” example, how does one go about making it possible to change parameters like color, emission and opacity in real-time (i.e. instantaneous update)? It needs to be fast, as it’s tied to an important game mechanic. The emission and opacity are secondary, the color is the primary concern.