diff --git a/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs b/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs index fd16f7f7..e2e06360 100644 --- a/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs +++ b/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs @@ -50,7 +50,7 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original var newFeatureVisualisation = new FeatureLineVisualisations() { feature = feature }; // Create visual with random color if enabled - UpdateMaterialInstance(); + lineRenderer3D.LineMaterial = GetMaterialInstance(); if (feature.Geometry is MultiLineString multiLineString) { @@ -66,20 +66,22 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original SpawnedVisualisations.Add(newFeatureVisualisation); } - private void UpdateMaterialInstance() + private Material GetMaterialInstance() { + Material featureMaterialInstance; // Create material with random color if randomize per feature is enabled if (RandomizeColorPerFeature) { var randomColor = UnityEngine.Random.ColorHSV(); randomColor.a = LayerData.Color.a; - lineRenderer3D.LineMaterial.color = randomColor; - return; + featureMaterialInstance = new Material(lineRenderer3D.LineMaterial) { color = randomColor }; + return featureMaterialInstance; } // Default to material with layer color - lineRenderer3D.LineMaterial.color = LayerData.Color; + featureMaterialInstance = new Material(lineRenderer3D.LineMaterial) { color = LayerData.Color }; + return featureMaterialInstance; } /// diff --git a/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs b/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs index 51e3dad7..c2f78cac 100644 --- a/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs +++ b/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs @@ -47,7 +47,7 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original var newFeatureVisualisation = new FeaturePointVisualisations() { feature = feature }; // Create visual with random color if enabled - UpdateMaterialInstance(); + pointRenderer3D.Material = GetMaterialInstance(); if (feature.Geometry is MultiPoint multiPoint) { @@ -63,20 +63,22 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original SpawnedVisualisations.Add(newFeatureVisualisation); } - private void UpdateMaterialInstance() + private Material GetMaterialInstance() { + Material featureMaterialInstance; // Create material with random color if randomize per feature is enabled if (RandomizeColorPerFeature) { var randomColor = UnityEngine.Random.ColorHSV(); randomColor.a = LayerData.Color.a; - pointRenderer3D.Material.color = randomColor; - return; + featureMaterialInstance = new Material(pointRenderer3D.Material) { color = randomColor }; + return featureMaterialInstance; } // Default to material with layer color - pointRenderer3D.Material.color = LayerData.Color; + featureMaterialInstance = new Material(pointRenderer3D.Material) { color = LayerData.Color }; + return featureMaterialInstance; } ///