- Home /
Is there a way to iterate all Scenes in a project and running some code for each of them?
Hi UnityAnswers Community,
I have to fix the position/scale (and maybe more) properties of an object in 30+ scenes, and I was wondering if there's some way to do it programmatically, like an editor script that loads, tweaks, saves, and iterates to the next level.
I seriously doubt there's a way, but my knowledge in editor scripting is quite limited at the moment.
Thanks for your time.
EDIT: I'm currently using this code. The object I have to change is a prefab present in each scene, so I attached a script to it with this function. Each time I double click a new scene and press CTRL+S to save it, it automatically tweaks the new values.
void OnValidate()
{
transform.rotation = Quaternion.identity;
transform.localScale = Vector3.one;
}
I'm still curious if there's a faster way to do that, maybe in situations where the scenes share no common object/prefab.
No I didn't know it, thank you :) I've already solved the problem with OnValidate, but I believe using PostProcessSceneAttribute can become handy in cases where there isn't any common object shared between scenes.
Now if there only was a way to load a new scene from within that function, we could batch the process.
Scene Load->PostProcessSceneAttribute->Tweaks->Save Scene->Load Scene with Index+1
You can create an editor script that iterates over a list of scenes, opening them, perfor$$anonymous$$g some changes on the hierarchy and then saving (check EditorApplication.OpenScene and EditorWindow.OnDidOpenScene)
Your answer
Follow this Question
Related Questions
Load specific scene in editor 2 Answers
3d mouse support in editor? 1 Answer
What is the proper way to draw previews for custom assets 2 Answers
Public Scene Variables not appearing in the inspector 2 Answers
Prevent selection of sub-object 1 Answer