Missing constructor for Mesh, can't access UnityEditor namespace

Felix Herbst 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 5

I'm trying out Bolt for the first time, and already hitting blockers. I went into it with a lot of expectations given the praise and support Bolt gets from Unity itself.

I wanted to apply it to the following, which is just a couple of lines with a custom script:
- take the mesh of an existing object
- modify its vertices
- save the modified mesh as a new asset.
- call that from a context menu without pressing play.

I hit the following blockers:
- seems Bolt code can only run in Play mode
- seems there is no Mesh constructor (forgotten? found the thread about you re-adding that for GameObject)
- can't get the UnityEditor namespace to show up even after adding it manually (for accessing AssetDatabase)
- seems I can't have a ContextMenu event or sth, at least have to build that manually

Am I missing something, or is that about it? (Mesh constructor missing a bug, the rest by design?)

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Pending Review

Hi Felix,

I'm sorry you're running into these blockers with editor scripting. Unfortunately, some design constraints prevent many operations from being functional in edit mode, because macro graphs aren't instantiated. There is work planned on the roadmap to further the editor-scripting side of Bolt, but in all honesty, it is not a priority at the moment based on the feedback from users.

I will look into the missing constructor for Mesh though, because that should be there. 

Also, have you added UnityEditor to your Assembly options and AssetDatabase to your type options? This is required for them to show up in the graph.

Fixed in Beta

The missing constructor will be fixed in v.1.3b3.

Hi and thanks! Will try it out as soon as I find time again. Also, I'll try adding the AssetDatabase type (I added the namespace but didn't know adding the type was necessary - what if I just want to have all types from that namespace?).

May I ask what the design constraint is for not instantiating the graph each time the source asset changes?

Extracting all types from a namespace will be possible in a future version (1.5 if all goes to plan)! 

Regarding instantiating the graphs during edit mode on source change... That's really complicated, both design and code wise. For example, if you're editing an instance of the graph (on an object that references a macro), and you change something, (how) does the macro get updated in the background? And does that change propagate to other instances? It's really not a trivial problem, also regarding multiple memory leak caveats that could occur from instantiating every graph and keeping everything in sync while in edit mode.

That being said, if I could find a solution to this, I would love it. It would indeed allow for editor scripting of all sorts, not just a simple button. I'm open to brainstorming (ideally in a separate thread!)