I’ve written a few editor “tool-type” scripts but as my project evolves I am more and more convinced that I want to do far more coding via scripts. And… I just had a project “collapse” when updating the Unity editor version for a VRChat world. VRC updated from 2019 to 2022 and 3 tries on conversion failed quite horribly. I’m still in the middle of comparing the two versions by walking the hierarchy and adjusting things.
As a sidenote, some prefabs were messed up, many objects in the hierarchy were missing, some had values modified and perhaps most disturbing a lot of the objects were renamed back to some older versions of themselves. Like Unity held onto the old names somewhere and decided to use them now.
But that is just my motivation for doing more of my coding in script code. I’m assigning a dozen (or more) gameobjects to a parent, adding them to an array in a parent object, incrementing a number to differentiate between them and such.
Imagine if this was all scripted. It seems that I could simply run the scripts that have already been shown to work. As it is I’m having to check every position, rotation (some rotations were reset to zero). Background colors, text alignment and even fonts. And if I’m adding say 10 items to a view I’m stuck decreasing the y value for each item added by hand. If I want to see what it looks like when I reduce the spacing I adjust them all by hand and back again when I don’t like the change.
So are there people who use vast amounts of editor scripts to generate/assemble objects? Are there any orientation videos ideally with “do this and don’t do this” types of hints?
I do procgen for a great deal of my personal games, simply because I’m not an artist. I do mostly runtime procgen, but sometimes editor-time procgen as well.
But to properly do procgen you definitely need to have a different much more iterative mindset to how you build stuff up in thin, small, well-tested layers, saving (committing to source control!) regularly as you get each piece working.
But for the day job we always do everything in the editor, at least 100% of the things that an artist might be called upon to tweak. The last thing I want to do as an engineer is fix things like “item x needs to be 3 pixels down.” For one I won’t do it right, for two, the artist can nail any other layout issues that result from that change.
The stuff we NEVER do in Unity is use UnityEvents from the editor. The reason is because if i write a script with button fields for OKAY and CANCEL, then some work gets done on the scene or prefab a year from now and those events get disconnected, I have absolutely no way to reason about what they should or used to be connected to.
I can’t even look at source control because the YAML encoding the button press usually has nothing useful that I can use to track the problem. It will largely either be fileID (whatever that is) or else GUID. And who knows what the rest of the YAML dreck does?
Instead, we drag a reference to the button into the script, then use btn.onClick.AddListener() to connect up code to whoever cares to be called about that button being pressed. Generally we name the field so well that it is unambiguous what has to be re-dragged back in here to make it work.
^ ^ This sounds like meta files getting renamed or forgotten to be committed to source control. The ONLY linkage that exists between a script and where it is used in Prefabs/Scenes is the metafile GUID.
When you update a package and they add / remove files, if they do it poorly, they can reuse GUIDs and cause issues. Here’s more reading:
SCRIPTS OR ASSETS ARE MISSING OR BLANK
ALWAYS move all Unity assets by using the Unity Editor. Any other way risks disconnecting the GUID in the meta file from the original file, and this will result in all connections to that asset being broken.
Some info about Missing script warnings, broken prefabs, GUIDs, renaming GUIDs, etc:
EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile, and hence why the metafiles ALWAYS MUST be source-controlled.
When Renaming: It is super-easy to inadvertently change the GUID by renaming outside of Unity. Don’t do that. Instead:
close Visual Studio (important!)
rename the file(s) in Unity
in Unity do Assets → Open C# Project to reopen Visual Studio
now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!
If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process. Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.
I‘m curious what the upgrade process is? Download and install what exactly - a store asset? A .unitypackage? A npm package? Something else?
Each has its own caveats.
Sounds like GUI. Sounds like IMGUI. If so you should look into UI Toolkit / UI Builder. Want to adjust spacing? You can do so via uss and its applied to all matching elements, with a live preview.
Even with IMGUI you have layout groups and all that.
If it‘s something else it still sounds like an inefficient workflow that could be improved even without scripting. You can often multiselect and mass edit. If you write custom scripts you should make sure the script supports that. If you find yourself doing that minor adjustment 100 times then an editor script can take care of that.
Thanks for the reply I’m hoping this turns into a discussion about the challenges, benefits and such. VRC has a CLI called Creator Companion which one isn’t obligated to use but it has some nice features for managing the libraries needed. It has a migration tool so I tried that. I tried exporting, creating a new project and importing that. Both resulted in major failures. As I mentioned above names of old game objects came back and silly things like rotations being reset to zero, positions reset not to where they are in my non-migrated project but where they were a week ago (or so).
In any case there aren’t going to be any caveats that will help me in the process. One would (I imagine) have to determine what causes, what to do what. I can re-enter all the values faster than trying to determine that and knowing what broke it doesn’t fix it.
I didn’t know that there were style sheets in Unity. I just watched a video and I’ll read the docs more to see if I can apply that in my project.
Meanwhile… style sheets aren’t going to populate lists with game objects right? I have (for example) about 100 game objects that represent videos that I can step through in-game. The object is a prefab the contents of the properties are not. They are often identical or mostly identical with (for instance) an increasing index value used as an id. Even the titles while obviously different exist in another document. I end up copying and pasting 100 titles. That’s not productive and if I wanted to change them all I’d have to do it again.
Luckily some of the larger lists of items maintained their settings so it was only a matter of adding them back to the array that lost the references.
I have often multiselected items and changed position values (z tends to become non-zero) but I again don’t need the y values all the same I needed them positioned relative to one another. I think style sheets will help but scripting should be able to do far more and isn’t limited to the UI.
A 3rd party migration tool that messes with your project? Oh dear …
IMGUI is the default, event-driven GUI system used by Unity. It supports both editor and runtime GUI.
It has been largely superceded by UI Toolkit, which supports USS stylesheets and themes and has a visual UI Builder. It’s super easy to work with.
I haven’t been able to determine what the cause of my migration issues is but as I said it is faster for me to simply correct things at this point. It had to migrate up several versions and there are 3rd party libraries used by VRChat which all needed to to be updated as well. Not a simple task in the best of circumstances. Others have used the tool, it went through some testing clearly so it could be something odd in my project. In any case. I get it now, UI Toolkit isn’t supported in VRChat development.
Coding editor scripts isn’t a UI layout thing so my general question remains. Automating routine property input tasks that can take considerable time and easily miss some minor adjustment of an id value would seemingly be valuable. I’m going to try it out but I hoped there were some developers doing it routinely.
My main point being (I think) if we use Visual Studio to refactor class, property and method names why wouldn’t we use code to populate an array, etc.? We don’t need to “refactor”. We could search through the project and type the change everywhere it was needed but we don’t as it is slow, inefficient and “you can miss one”