My current project has some editor scripts that I run just prior to run/build, which dynamically creates some game objects in my main scene based on configuration. I don't want these objects to clutter up version control however, so I delete them prior to saving the project and committing changes to the repo. Currently I'm doing both of these steps manually, but this seems like the kind of thing that should automated. Is there a way to automate running these scripts prior to a Build and then deleting the constructed objects (presumably can create another script to help with this) prior to saving the project?


1 Answer 1


I don't know if it'll work for your specific use case, but note that there's the PostProcessBuild attribute for editor scripts that run automatically after a build. I use that to edit the XCode project generated by an iOS "build".

Another approach is to write a script that executes the build, and that script can probably do cleanup after a build too. Like, I routinely write editor scripts that add a "Custom Build" option to the File menu, and then that script does a bunch of stuff before calling BuildPlayer. Assuming the BuildPlayer method is synchronous (I don't know if it is, I've never tested this) then that script could also do more stuff after BuildPlayer.

  • \$\begingroup\$ A post-build for cleanup could help, though people might also run this generate script manually before running a scene in the editor. I should look into whether there are editor methods to Save the project, as I could potentially create custom Build and Save menu items, then just tell people to use those instead of the defaults. Still semi-manual, but getting people to consistently use one click rather than a few clicks is probably easier. \$\endgroup\$
    – Dan Bryant
    Commented Jul 30, 2021 at 14:53
  • \$\begingroup\$ It sounds like you want to do the second thing then, either by itself or in addition to the post-build script. That is, you have the editor script that generates objects also do the build. Then it's impossible to run the generate script without doing a build. \$\endgroup\$
    – jhocking
    Commented Jul 30, 2021 at 15:01
  • \$\begingroup\$ Hmm, possibly, though I sometimes run the generator, play around in play mode for a bit, tweak the generator settings and regenerate, play some more, etc. The Build process isn't too long, but not ideal to run it if not necessary. Failing to generate before Run is also a possible mistake, but it's lower impact (only impacts the developer testing and not any downstream people impacted by a bad build or a bloated commit) \$\endgroup\$
    – Dan Bryant
    Commented Jul 30, 2021 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .