Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | chuckeles |
In my game, I have a car scene (object) which then gets instantiated during gameplay many times. Each car has a separate state for its breaks, and when the car is breaking, I want its tail lights to change their emission strength.
How should this be done properly in Godot?
The way I’m currently doing this in the game is that, in a script for the tail lights, I call material = material.duplicate()
to make a unique material for the car. Then in the process function, I change the material’s emission as necessary using material.emission_strength
. This feels like it isn’t the proper way to go, and I expect it to not be performant to duplicate the material each time a new car is spawned. How can this be improved?
Have you tried assigning a unique Material
to the original object, and then tried changing the emission_strength
on the instantiated object via a Material
override?
Ertain | 2022-04-04 23:38
How do you do that? I don’t see any material override option in the editor.
chuckeles | 2022-04-10 17:55
Okay, actually now I see there’s a material_override
property which I can set. But it looks like it needs another material, which means that I still need to duplicate the existing car material anyway.
Actually, now that I’m thinking about it, I can have 2 premade materials - one for regular tail lights and one for breaking tail lights. Then I can set the material_override
to the breaking material while breaking, and to null
when not…
chuckeles | 2022-04-10 18:01
Yep that worked!
chuckeles | 2022-04-10 19:02