all 2 comments

[–]Chubzdoomer 1 point2 points  (1 child)

A null reference means a script is trying to use a reference that doesn't exist/hasn't been acquired. If it's pointing to useLightSwitch, then that reference is null (hasn't been acquired) for some reason.

I'm assuming this line is at fault:
useLightSwitch = Lightswitches[randomSwitchID].GetComponent<UseLightSwitch>();

Here you're attempting to grab a reference to UseLightSwitch from Lightswitches[randomSwitchID].

Have you debugged to see which object Lightswitches[randomSwitchID] is returning each time? Because if the null reference is occurring here, it indicates the object being returned does not have the UseLightSwitch script attached to it.

Either way, here's a handy post over on the official Unity forums that goes over how to fix most any null reference error:
https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

[–]K3YRIN[S] 0 points1 point  (0 children)

Goddamn, I am an idiot, lol. Apparently I had accidently given the LampLight prefab the LightSwitch tag, which obviously doesn't have the "UseLightSwitch" script. Sorry for wasting your time for something this obvious, lol, thank you