Configure shadows when the scene starts
Updated
At startup a script switches on a lamp’s shadow map, lets a crate receive shadows and gives the floor a soft contact shadow: Light Shadow, Shadow and Contact Shadow components set from a Behavior script.
Orbit around to see the lamp's shadows and the soft contact shadows under each object. Drag to orbit the camera, scroll to zoom.
Configure shadows when the scene starts
#pragma lifecycle(startup)
function startup() { // A crisp shadow from the lamp that covers only the room. const lampShadow = findEntity('Lamp').getComponent(LightShadowComponent); lampShadow.setEnabled(true); lampShadow.setProps({ mapSize: 1024, range: 12, bias: -0.0004 });
// The crate now also receives shadows from other objects. findEntity('Crate').getComponent(ShadowComponent).setProps({ receive: true });
// The floor draws a cheap, soft contact shadow under what stands on it. findEntity('Floor').getComponent(ContactShadowComponent).setProps({ receive: true, quality: 'low' });}How it works
Section titled “How it works”The script is explained step by step in Configure shadows when the scene starts.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
ShadowSetup.xrproj