- Home /
How to turn off render shadows for all childs of an empty gameObject
I have a model with several empty gameObjects with several cubes in them, and I want to turn off casting shadows just for those cubs in those empty gameObjects without going in and manually disabling all of them(not during runtime).
Is there an easy shortcut I can do to accomplish this, or do I need to use a script/do it manually?
Thanks in advance!
Answer by Freesmith · Jun 19, 2019 at 12:51 AM
you can do it in 5 steps without coding :
copy all empty game object that contain cubes into separate scene ( )
in hierarchy tab in the search bar type t:meshrenderer (this will get you the list of game objects with mesh renderer component on them)
select all game objects in the list (in the inspector tab you will get mesh renderer component display )
in cast shadows field select off (clear the field in the search by clicking x), so the original hierarchy view returns
select and paste those back in the origin scene
If your cubes have "cube" in their names you can isolate them in search by typing "t:meshrenderer cube", and don't need to copy them to another scene here is the screenshot
Answer by unity_Y9AfbvAM22aTww · Jun 18, 2019 at 06:25 PM
the fast way, just create a simple script
public class JustModifyMeshRenderers : MonoBehaviour{
public bool castShadowsInChildren;
void OnValidate() { //and here get the children and modify it using the castShadowsInChildren value //when you modify in the inspector the value of the boolean you will run this function
}
}
Answer by harleydk · Jul 02, 2020 at 07:35 PM
Perhaps - haven't tested it - LINQ would be useful here?:
var meshRendersInAvatar = avatar.GetComponentsInChildren<SkinnedMeshRenderer>();
//meshRendersInAvatar.AsParallel().ForAll(m => m.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off);
Your answer
Follow this Question
Related Questions
Mesh darker than asset 1 Answer
Spotlight not shining on certain objects 1 Answer
How to change one child object to another with the same armature? 0 Answers
Have an empty's position follow one of it's children's positions? 2 Answers
URP 2D lights with Mesh Renderer?,URP 2D Light for Mesh Renderer? 0 Answers