Vehicles with dynamic lights e.g. headlights, indicators, brakelights, reverse lights

Recently I made the switch from Unity3d to UE4 and have been finding it increasingly difficult to recreate what i had in Unity.

What i want to have is multiple vehicles that have each have headlights that can be manually turned on and off as well as reverse lights that come on when reversing and brake light that come on when braking, etc. you get my flow here.

At the moment i am trying to have it so that i have a base CarLights material that has the material logic all in there then i have one material instance for each car (e.g. bmw 5 has BMW_5_Lights) which has the CarLights material as it’s parent then from that material i have more instances such as headlights, brakelights, etc that have the BMW_5_Lights material instance as their parents. this way all light materials for each car can use one texture and i can change the emissive intensity individually.


This will cause an issue when you have more than one vehicle as modifying the parameters for one BMW 5 will change the material which will be applied to all of the BMW 5’s in the game.

Another way i thought of was to have mesh components on the car’s actor and enable/disable them i could import the light meshes seperately and apply them in my initialization function, this would be a good way to go as i could put light components as children of the mesh components but i dont want to have to import loads of meshes for each car considering there will be loads of cars ingame. This is essentially what i did in unity as you can see in these to screenshots:


Does anyone else have an interesting workaround or other method of achieving this?

P.S. i dont mind if the resolution uses blueprints or c++ but please note i will have to use c++ to do this eventually so blueprint only solutions wont work

you might want to have a look at the free vehicle racing demo , i think they have the sort of setup that you need

This is simple enough to do. Attach a moveable spotlight on the outside of the mesh (but as close as possible to avoid shadowing artefacts), and use Blueprints to turn those on/off when you want them to (easy enough to do in code as well).

For the emissive light material, just use material parameters to switch between the different states. You can create a Dynamic Material Instance in Blueprint (or code), assign it to the mesh and then control the various parameters through code. A simple lerp/like switch for on/off would suffice. Hard to know how much detail to go into as I don’t know what your level of UE4 knowledge is.

I promise you one way or the other, it’s ****-site easier and more flexible than Unity’s method by the looks of it.

Further to what TheJamsh has mentioned, I created the components and event graph like this:





I used lights for the brakes/reverse lights but using an emmissive material would work just as well (and probably a better solution for brake lights) using material parameters. You would need to set up the mesh to use multiple material slots so that the brake lights are one material, reverse lights another, the body of the car another etc. but for the headlights you will want to use spotlights. Hope this helps!

I did actually take a look at that but they have only implemented brake lights using mask but that wouldnt work for me as i need so many lights and there are only three channels to use as a mask

The problem with that is im spawning my vehicles at runtime and the vehicles then create themselves by assigning themselves a mesh and handling data so i can’t do it that way

You can give separate material ID’s to different lights of your vehicle and then use separate materials or material instances. Assigning material ID’s is something you’ll need to do in your modeling software of course.

Take a look at this:
You can easily create dynamic material instances at runtime, I think this is what TheJamsh suggested.

Im not sure if i didnt explain it very well but thats what im doing at the moment. i explained this in the third paragraph/ the problem is if i want to spawn more than one instance of one vehicle type eg bmw 5 series then they will all be using the same materials and so when i turn the headlights on in one vehicle they will turn on for all of the bmw 5 series’

Using a DynamicMaterialInstance created in the construction script of the vehicle to change this value does not apply the change to every other vehicle. With that created you then use a “Set Scalar Parameter” node from the event graph to turn set the emmissive strength to turn it on or off. This will only affect that instance of the vehicle, using a regular material instance will affect them all, but not a DynamicMaterialInstance.

You can see this in action by placing multiple copies of the truck in the VehicleGame sample, each one is independent.

Ohh i see, so it essentially creates an instance of the material that belongs to that class and applies it to the mesh. i thought it was just a pointer to the material being used by the mesh. this is interesting because i can use this method now. would i be right in saying that this is slower than the other way as there will be loads of different materials instead of having one material applied to loads of vehicles?