How to swap cubemap when game environment changes

I'm a unity newbie and need a little help...

I have two different environments the user can choose from. I have generated a cubemap for each environment. When the user switches environments, I need to swap out the cubemap being reflected in the scene. Here's some ideas:

  1. Create 2 materials for all of the assets and assign the material at runtime, when the scene changes. The problem I have with this is these are large scenes with tons of assets. How would I go about doing this without having to go through every single object in the scene.

  2. Find a way to re-assign the cubemaps dynamically when the user switches environments. Maybe loop through all scene materials looking for the presence of one cubemap, then replace it with the other.

Seems like that's all I can come up with, and I'm leaning towards #2. Just curious if it would cause a performance hit. Anyone have a better suggestion?


Using concept #2 above...

// replaces the reflection cubemap for the selected environment (garage or gallery)
public void setReflectionMaps(Cubemap cubeMap) 
    // get all of the  mesh renderers
    var renderers = truckGO.GetComponentsInChildren<Renderer>();
    foreach (Renderer r in renderers) {
        // get the material for each renderer
        Material mat = r.sharedMaterial;

        // check if the material has a cubemap
        if (mat.HasProperty("_ReflectionMap")) {
            // replace existing cubemap


Need Your Help

Set iframe to height of content for remote content

iframe height xss

The question of how to make your iframe fit 100% of your content (using JavaScript) has been answered on the forum already... for iframes displaying content from the same domain only.

is there any way to distribute ios applications outside app store?

ios iphone ipad app-distribution

Is there any way to distribute ios applications through my own website, not using app store?