UE3 - UDK Toggable flashlight socket

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

TheChronus

New Member
Jan 2, 2013
2
0
0
Hello.

Alright, so i was following someones code for creating a toggable flashlight.
I'm fairly new to coding, so i'm not 100% sure on how to manage this.
I want to make it so the linkgun has a toggable flashlight on it.
All i did was stick this in its own class, give the linkgun the light socket (not sure if i did it right), and test it out in game, but to no avail.
If someone could point me in the right direction or let me know how to implement it, i would appreciate it.

Here is the code for reference.

Code:
class FlashLightPawn extends UTPawn; //change to extend Pawn or UDKPawn if you want but give it a skelital mesh with a reference variable called Mesh

var SpotlightComponent Light;  //the actual light
var name Light_Socket;  //the name of the socket to attach to
var bool LightsOn; // boolean to turn light on and off

//use a keybind in UDKGame/Config/DefaultInput.ini
exec function LightOn()
{
  //alternate between true and false 
  LightsOn = !LightsOn;
   
    //if true attach the light
   if (LightsOn)
   {
     //if you want it to be on the weapon use Weapon.Mesh.AttachComp.....
     Mesh.AttachComponentToSocket(Light, Light_Socket); 
     //set up its properties (these properties were almost from a post on here, cant remember who from)
     Light.LightShadowMode = LightShadow_Normal;
    Light.ShadowFilterQuality = SFQ_Medium;
    Light.ShadowProjectionTechnique = ShadowProjTech_BPCF_Medium;
    //subtlle light shaft to simulate some kind of flashlight corona
    Light.bRenderLightShafts = true;
    Light.BloomScale = 0.2;
    Light.RadialBlurPercent = 1;
   }
   else if (!LightsOn)   //false so detach the light
   {
      Mesh.DetachComponent(Light);
   }
}

DefaultProperties
{
//declare the light component	
Begin Object class=SpotLightComponent Name=MyLightComponent
          InnerConeAngle=10
          OuterConeAngle=26.2
          Radius=92000
          Brightness=2.00000
          LightShaftConeAngle=89
          //bRenderLightShafts=true
          LightColor=(R=141,G=247,B=155)
          CastShadows=true
          CastStaticShadows=False
          CastDynamicShadows=True
          bCastCompositeShadow=False
          bAffectCompositeShadowDirection=False
    End Object
//get a reference to the object
  Light=MyLightComponent
//the name of the socket
  Light_Socket="LightSocket"
}
 

TheChronus

New Member
Jan 2, 2013
2
0
0
Thanks for the reply.
I thought I did originally add the socket to the mesh. I went into UDK and added the light socket to the linkgun. It didn't work, so i'm obviously doing it wrong.
Could you possibly give an example of how i can add the light socket to a mesh?
 

VendorX

Member
Aug 2, 2010
231
6
18
BXL/Paris
Well, your FlashLightPawn is extending from UTPawn where Mesh is a Pawn.Mesh - not Weapon.Mesh... Basically, simething like FlashLight should be an Inventory, which you can drop/pickup. Use existing in every weapon MuzleFlashShocket, attache to it, add some offset and because it's Inventory, any exec function will be called. Put some log to see what happen...