• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by NeatWolf · Mar 10, 2014 at 09:14 PM · editorscenesiteratebatch

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NeatWolf · Mar 17, 2014 at 02:23 PM 0
Share

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

avatar image frarees · Mar 17, 2014 at 02:32 PM 0
Share

You can create an editor script that iterates over a list of scenes, opening them, performing some changes on the hierarchy and then saving (check EditorApplication.OpenScene and EditorWindow.OnDidOpenScene)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by frarees · Mar 17, 2014 at 10:46 AM

Have you tried PostProcessSceneAttribute?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting Scenes in Project From Editor 2 Answers

Load specific scene in editor 2 Answers

Cannot close/unload a scene that is open in editor during playmode (using C# code)? 3 Answers

3d mouse support in editor? 1 Answer

What is the proper way to draw previews for custom assets 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges