UE3 - UT3 Custom Vehicle Help

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

RevBillyG

Taking over the world.
Nov 10, 1999
1,262
6
38
Hey all. Since I'm a total dunce at all things script-rated, I'm stuck :(

I presently have a working vehicle ingame (managed to get that far :p) but I'd like to be able to make the headlights and taillights come on when the player enters the vehicle.

I've been looking around for days for the answer and have poured through the hellbender and scorpion classes and I'm still not much wiser.

The vehicle texture is set up thusly:
0) Main body texture
1) Number plate
2) Headlight (I'll do the taillight later when I figure out the headlight)

All I want to do is, when the player enters the vehicle, swap the unlit Headlight texture for a lit one and back to the unlit one when they leave.

Sounds easy...but it's either really complicated (probably not) or I'm stupid (very likely)

I can use a materialinstance for this and I know how to set that up in the Ed and I also know how to call from uscript

Code:
var MaterialInstanceConstant HeadLightMaterial;
HeadLightMaterial = MaterialInstanceConstant'VH_HippyBus.Materials.HeadLightInstance';
		//Turn on Headlights
		HeadLightMaterial.setVectorParameterValue('Headlightemissive',MakeLinearColor(1,0,0,1));
	}

But maybe it's easier just to swap textures.

I haven't a clue how to actually make this work when the player enters and leaves the vehicle tough.

Any help would really be appreciated. :)
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
All Pawn instances (i.e. also vehicles) need to create their own material instances on spawn so they don't affect others that use the same material. Basically you need to create a MaterialInstanceConstant at runtime and specify the default material as its parent. If you extend from UTVehicle, you should get that automatically, but then your code as you posted it accesses the wrong material.

UTVehicle does the material instance stuff to display per-vehicle damage overlays, so the corresponding function is called CreateDamageMaterialInstance() and stores the created material instance not only in the mesh's materials array, but also in the UTVehicle's DamageMaterialInstance[0] array slot. If that sounds too weird for you, just access the material via Mesh.Materials[0] instead.

A good event for modifying these materials might be DrivingStatusChanged().
 
Last edited:

RevBillyG

Taking over the world.
Nov 10, 1999
1,262
6
38
Thanks Wormbo :)

I've seen reference to DamageMaterialInstance[0] in the Hellbender/Scorpion script and saw that it was used to change the headlight material status there.

So, I need to create the MaterialInstanceConstant in script and then call that Material afterwards rather than referencing the it from the upk file?

As for the vehicle driving status, I see there's a tag call enginestart and engine stop. There's also another called bDriving (I think, I'm on my laptop at the moment so can't check). Could I use those?

As you see, I'm clueless at scripting :)
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
I think bDriving is the value you will want to check in DrivingStatusChanged(). It should be set when the vehicle has a driver, which is when you will want to activate the lights.
Unfortunately there aren't that many code examples in UT3, as most of this was moved to native for some reason. I recommend getting some inspirations from UT2004 code here. Headlights and tail/brake/reverse lights are done via coronas there, but the activation logic is implemented in functions and events that still exist in UT3.
Basically DrivingStatusChanged() enables or disables the lights, while Tick() updates the tail lights for braking and reverse gear. The logic obviously works differently when applied to coronas, but maybe it'll help you get some general ideas, how to do it.

 

RevBillyG

Taking over the world.
Nov 10, 1999
1,262
6
38
Update. Fixed :)

Used DrivingStatusChanged() in order to attach different lit meshes to the vehicles.