HotReload causes apparent script duplication (?) [SOLVED]

UPDATE: i kinda of solved this, i think its worth pointing this post in the future.

I’m testing a new lighting system that has material support this time. While tweaking values from inside the editor (the scripts gui) i found out that my ligth sources were being duplicated for some reason. Specifially, this system has point and directional lights (like sun and a lamp). My scene has 3 point lights and 2 directional lights and when i update one of the lamps script it seems like the number of point lights is duplicated. This is the log:
image
its like this in the code:
image

When updating it seems like the engine/editor just duplicated my point light objects or their scripts or something alike. I dont really know what it is, as of now i will try to find if im not doing anythig wrong in the scripts and test if this happens to the directional lights as well.

This problem was solved this way: what happened was that each light source (directional or point) had a script attached. said script had a local table that store all things important to a light source. PROBLEM WAS, this table was literally a local source = {} this created an error in which this table was sorta “static”. By that i mean, that this table was shared between the objects that had the script. The solution was to put this table inside the self variable, in the init function. Now i can hot reload properly.

Moral of the story: always use the self variable whenever possible.

3 Likes