# ExtractFromScene

> Extracts all relevant scene data for light transport calculations from the currently open scenes.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.LightTransport](/engine/6000.3/script-reference/unityengine/lighttransport.md)
* **Assembly:** UnityEditor

## ExtractFromScene(BakeInput)

Extracts all relevant scene data for light transport calculations from the currently open scenes.

```csharp
public static bool ExtractFromScene(out InputExtraction.BakeInput bakeInput)
```

### Parameters

**** (\[BakeInput]\(/engine/6000.3/script-reference/unityengine/lighttransport/inputextraction/bakeinput)): Output parameter that receives the extracted scene data.

### Returns

| Type                                                          | Description                                                          |
| ------------------------------------------------------------- | -------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if extraction completed successfully, false if errors occurred. |

### Remarks

This method scans all currently open scenes and extracts objects that affect global illumination calculations. It processes:

**Geometry:**

* [MeshRenderer](/engine/6000.3/script-reference/unityengine/meshrenderer.md) components with static flags or "Contribute GI" enabled.
* [Terrain](/engine/6000.3/script-reference/unityengine/terrain.md) objects with baked lighting enabled, including trees.
* Associated [Material](/engine/6000.3/script-reference/unityengine/material.md) properties and textures.

**Lighting:**

* [Light](/engine/6000.3/script-reference/unityengine/light.md) components configured for baked or mixed lighting.
* Environment lighting and skybox settings.
* Light probe groups ([LightProbeGroup](/engine/6000.3/script-reference/unityengine/lightprobegroup.md)).

**Output Data:** The resulting BakeInput contains preprocessed data ready for [InputExtraction.PopulateWorld](/engine/6000.3/script-reference/unityengine/lighttransport/inputextraction/populateworld.md). Objects not marked as static or not affecting GI are automatically excluded.

**Performance Note:** This operation can be expensive for large scenes as it processes all geometry and builds internal data structures.

### Examples

```csharp
// Extract scene data for baking
bool extractionSuccess = InputExtraction.ExtractFromScene(out var bakeInput);
if (!extractionSuccess)
{
    Debug.LogError("Failed to extract scene data for light baking");
    return;
}

// Proceed with context creation and world population
using var context = new RadeonRaysContext();
context.Initialize();
var world = new RadeonRaysWorld();
using var progress = new BakeProgressState();

bool populateSuccess = InputExtraction.PopulateWorld(bakeInput, progress, context, world);
Assert.IsTrue(populateSuccess);
```

## ExtractFromScene(BakeInput, bool)

Extracts all relevant scene data for light transport calculations from the currently open scenes.

```csharp
public static bool ExtractFromScene(out InputExtraction.BakeInput bakeInput, bool probesOnly)
```

### Parameters

**** (\[BakeInput]\(/engine/6000.3/script-reference/unityengine/lighttransport/inputextraction/bakeinput)): Output parameter that receives the extracted scene data.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to only extract data needed for baking probes. Setting this to false will skip lightmap packing.

### Returns

| Type                                                          | Description                                                          |
| ------------------------------------------------------------- | -------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if extraction completed successfully, false if errors occurred. |

### Remarks

This method scans all currently open scenes and extracts objects that affect global illumination calculations. It processes:

**Geometry:**

* [MeshRenderer](/engine/6000.3/script-reference/unityengine/meshrenderer.md) components with static flags or "Contribute GI" enabled.
* [Terrain](/engine/6000.3/script-reference/unityengine/terrain.md) objects with baked lighting enabled, including trees.
* Associated [Material](/engine/6000.3/script-reference/unityengine/material.md) properties and textures.

**Lighting:**

* [Light](/engine/6000.3/script-reference/unityengine/light.md) components configured for baked or mixed lighting.
* Environment lighting and skybox settings.
* Light probe groups ([LightProbeGroup](/engine/6000.3/script-reference/unityengine/lightprobegroup.md)).

**Output Data:** The resulting BakeInput contains preprocessed data ready for [InputExtraction.PopulateWorld](/engine/6000.3/script-reference/unityengine/lighttransport/inputextraction/populateworld.md). Objects not marked as static or not affecting GI are automatically excluded.

**Performance Note:** This operation can be expensive for large scenes as it processes all geometry and builds internal data structures.

### Examples

```csharp
// Extract scene data for baking
bool extractionSuccess = InputExtraction.ExtractFromScene(out var bakeInput);
if (!extractionSuccess)
{
    Debug.LogError("Failed to extract scene data for light baking");
    return;
}

// Proceed with context creation and world population
using var context = new RadeonRaysContext();
context.Initialize();
var world = new RadeonRaysWorld();
using var progress = new BakeProgressState();

bool populateSuccess = InputExtraction.PopulateWorld(bakeInput, progress, context, world);
Assert.IsTrue(populateSuccess);
```
