Jump to content

Light Creation Guide?


Recommended Posts

Hi,

I'm working on a part for Infernal Robotics that among other things will feature a light (see here). So far I've managed to get the part in-game with an emissive and spotlight, but am having difficulty figuring out the next step of actually making it controllable in-game. I presume I need some sort of animation to control the intensity, but can't figure out how to go about this in the current Unity version (4.3), and haven't found any concise guide on the process. Edit: I already have ModuleLight assigned to the part.

Could anyone shed some light (pun intended :P ) on this matter please?

Thanks,

-Zodius

Edited by ZodiusInfuser
Link to comment
Share on other sites

add a light in Unity and put it in the appropriate place in your part hierarchy. then add this module to the part

MODULE
{
name = ModuleLight
lightName = spotlight //name of the light you added in Unity
useAnimationDim = true //use BrightenSpeed and DimSpeed settings.
lightBrightenSpeed = 2.5
lightDimSpeed = 2.5
resourceAmount = 0.04 //amount of EC consumed per second
animationName = LightAnimation //Emissive animation
useResources = true // set to false of you don't want light to consume EC
}

that should make the light function like stock lights. and respond to U-key

Edited by nli2work
Link to comment
Share on other sites

add a light in Unity and put it in the appropriate place in your part hierarchy. then add this module to the part

MODULE
{
name = ModuleLight
lightName = spotlight //name of the light you added in Unity
useAnimationDim = true //name of the light animation if applicable
lightBrightenSpeed = 2.5
lightDimSpeed = 2.5
resourceAmount = 0.04 //amount of EC consumed per second
animationName = LightAnimation //what the toggle name is in Action Group settings
useResources = true // set to false of you don't want light to consume EC
}

that should make the light function like stock lights. and respond to U-key

I should have mentioned, I have already got the module assigned to the part, but the spotlight and emissive still aren't controllable (will update OP to clarify).

Link to comment
Share on other sites

I should have mentioned, I have already got the module assigned to the part, but the spotlight and emissive still aren't controllable (will update OP to clarify).

I got couple of the settings wrong in the last post.

My guess is your Emissive animation is controlling the Light as well? try setting "useAnimationDim = false"; it maybe the LightModule is fighting your emissive animation for control over the light. or remove any curves that control the light in Unity animation before exporting.

alternative is to use ModuleAnimateGeneric, key the light and emissive in one animation. down side is that won't respond to U-key and possibly Action groups.

Link to comment
Share on other sites

I didn't have an animation on my part when I first posted, and I'm not entirely sure on how to set one up in 4.3. In-Game the light responds to the color tweakables in the VAB, but is always on. Oddly both Light On and Light Off appear as toggleables, with exceptions occurring when they're pressed:

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)

NullReferenceException: Object reference not set to an instance of an object
at ModuleLight.LightsOff () [0x00000] in <filename unknown>:0
at ModuleLight.OnStart (StartState state) [0x00000] in <filename unknown>:0
at Part.ModulesOnStart () [0x00000] in <filename unknown>:0
at Part+ .MoveNext () [0x00000] in <filename unknown>:0

(Filename: Line: -1)

IR.EndEffector(Clone) added to ship - part count: 4

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)
stage count is: 0

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)

NullReferenceException: Object reference not set to an instance of an object
at ModuleLight.LightsOff () [0x00000] in <filename unknown>:0
at BaseEvent.Invoke () [0x00000] in <filename unknown>:0
at UIPartActionButton.OnClick () [0x00000] in <filename unknown>:0

(Filename: Line: -1)

NullReferenceException: Object reference not set to an instance of an object
at ModuleLight.LightsOn () [0x00000] in <filename unknown>:0
at BaseEvent.Invoke () [0x00000] in <filename unknown>:0
at UIPartActionButton.OnClick () [0x00000] in <filename unknown>:0

(Filename: Line: -1)

My CFG is idential to what you posted (except my light is called Light).

And here's my unity scene

_61bdecba3912497c8bc4bdbd58ccb055

Edited by ZodiusInfuser
Link to comment
Share on other sites

very strange. I've got no ideas... shots in the dark: maybe try childing the Light to Body? from the NullRef looks like the Light isn't being written out to the MU. could also try renaming the Light to spotlight, shouldn't make any difference, but who knows.

both buttons being visible in Editor usually mean the Module's loaded correctly, but it doesn't have to correct parameters to work with. and in this instance, the only one is Light.

it could be that you supplied animationName in config, the module is looking for an animation in the MU but not finding one.

I'd start with trying the simplest config and add to it bit by bit till it stops working

MODULE
{
name = ModuleLight
lightName = spotlight //name of the light you added in Unity
resourceAmount = 0.04 //amount of EC consumed per second
useResources = true // set to false of you don't want light to consume EC
}

Edited by nli2work
Link to comment
Share on other sites

Thanks nli2work. I took your suggestion and stripped it down to the basics, and built up from there. I now have the light an emissive working correctly!

_e225c58cdfcc4df9a6945b35e12d232b

_2e78f4cf31b04a97b5cb86a829dd76e1

For others, here's the rough steps I followed to get this working:

  • Place the light under the mesh with emissive
  • Add an animation component to the mesh object
  • Open the animation window
  • Add a curve for Emissive Color Alpha, and for Light Intensity (you'll be prompted to create a new animation file)
  • Set the key frames for the start to zero, and the end to what is wanted
  • Save the animation (or save the scene and the anim gets saved with it)
  • Follow the steps in this thread to allow emissive animations to export form Unity 4.3: http://forum.kerbalspaceprogram.com/threads/85221-Tutorial-Fixing-emissive-animations-for-Unity-4-3
  • Compile the model
  • Create the CFG and add the ModuleLight code nli2work posted above

Note that if you just want the light to come on instantly, and there to be no emissive then the four lines directly above are sufficient. As soon as you add an animation, KSP no longer controls the light intensity (just colors).

Link to comment
Share on other sites

I'm trying to get a light to work. Essentially what I am trying to do is make a light attached to a landing leg. The problem is I want it to be attached to the leg, so it will move /shine in conjunction with the legs position (deployed vs retracted). If I add the the light in via unity I don't know how to attach it to the blender animation. Any ideas?

Note1: The animation for the landing leg is done through blender

Note2: I figured out how to make a light turn on and off via animations thanks for that "useAnimationDim = false". Couldn't figure out why it wasn't working till I saw that and tried it.

Link to comment
Share on other sites

just drag the light and child it under the leg part you want the light on. Since the light only comes on when the leg is deployed, it'd be easier to animate the light so it's linked to the leg animation.

once you import the blender file, duplicate the animation. assign the new animation clip to your game part. check that it works as before. add light to your heirarchy, then add light intensity and range key frames to the animation clip before exporting. set up the leg using the lander leg module and you'll have a leg with light that responds to the G-key in game.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...