Unable to set multiple lights to one object

I am trying to use setLight() to set multiple spotlights on a single object, but it appears that the second light I set overwrites the first one. They both work fine when I set them individually, but not when I try to use them both.
Thanks for any help I may get.

Hmm… It seems to be working on my end.

Could you perhaps post the relevant portion (or portions) of your code, please? It may be that there’s something there that is causing the issue that you’re seeing.

I have already changed the code, but I forgot to mention that it worked when I used Point Lights but not with Spotlights. Is that possibly a bug? Is there a way to fix it? I tested each light individually and they worked, and I applied them the same way as with the point lights.

As I said, it works on my end–and to clarify, that is with spotlights.

I’m still then inclined to guess that the problem lies in the code somewhere.

However, it is perhaps worth asking: What version of Panda are you using, and what version of Python? If you’re using an older version of Panda (or an in-development version) then perhaps it is a bug that’s not in the current stable version of the engine. Or if you’re using an unexpected version of Python, perhaps there’s an interaction there.

There wasn’t much to the code. It looked something like this(Without some positioning):

model = self.loader.loadModel('path')
model.reparentTo(render)

lens = PerspectiveLens()

light1 = SpotLight('Spotlight1')
light1.setColor(1, 1, 1, 1)
light1.setLens(lens)
light1.getLens().setFov(100, 100)
light1np = render.attachNewNode(light1)

light2 = SpotLight('Spotlight2')
light2.setColor(1, 1, 1, 1)
light2.setLens(lens)
light2.getLens().setFov(100, 100)
light2np = render.attachNewNode(light2)

model.setLight(light1np)
model.setLight(light2np)

I’m not sure if I was supposed to set them to different lenses and I don’t remember if I did. Could this be the problem? I am using python v3.7.9 and Panda3d v1.10.11x64

Hmm… I’m not sure. It seems plausible, but some testing on my end seems to indicate that it doesn’t incur such a problem.

You’re using a slightly later version of Python than am I–whether there might be a relevant difference there I don’t know, I’m afraid–and a similar-looking version of Panda.

For reference, here’s code that works on my machine, I believe:
(Excluding things like setup and code to rotate the model.)

        light1 = Spotlight("light 1")
        light1.setColor((0, 1, 0, 1))

        lens = PerspectiveLens()
        light1.setLens(lens)

        light1NP = render.attachNewNode(light1)
        light1NP.setPos(15, 10, 0)

        light1NP.lookAt(self.model)
        self.model.setLight(light1NP)
        
        light2 = Spotlight("light 2")
        light2.setColor((0, 0, 1, 1))

        lens = PerspectiveLens()
        light2.setLens(lens)

        light2NP = render.attachNewNode(light2)
        light2NP.setPos(-15, 10, 0)

        light2NP.lookAt(self.model)
        self.model.setLight(light2NP)

I am creating a separate PerspectiveLens there–but commenting that line out doesn’t seem to have a noticeable effect, to my eye.

So, overall very strange! Unless there’s something elsewhere in your code that might be interfering, I don’t know why you’re finding spotlights to not work!

Perhaps others on the forum will have further ideas!

Thanks for the help, I’m not sure what the problem is, but I have switched to Point Lights and they seem to be working fine.

1 Like

That’s fair.