0 votes

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?

Godot version v3.4.2
in Engine by (85 points)

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?

How do you do that? I don't see any material override option in the editor.

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...

Yep that worked!

1 Answer

0 votes

Yeah, there is an editor function for that.
Get into your car scene, -> material -> and choose "resource" property tab there -> set "localtothescene" to true. The same can be done in code by "makelocal" method.

by (5,557 points)

I don't see any make_local function in code, nor any "local to the scene" option in the editor. I'm using Godot 3.4: https://docs.godotengine.org/en/stable/search.html?q=make_local&check_keywords=yes&area=default

It is almost 1st sentence there.
or it was local to the scene in code and make local in editor :). In editor every resource has
Resource tab, it is a bit hard to see. If You click on it , it will show additional options, like resource path and make local.

Oh I see! I was looking in the wrong place – I was searching the properties of the mesh node, whereas this is a property of the resource. This will suit my needs exactly, thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.