I spent a big chunk of today creating a solution to the “I can’t move the pivot of my objects” problem. The Editor script I wrote allows you to move the pivots of your Game Objects easily, however this is only the initial version so expect a couple limitations.
This is a great idea and I’ve definitely found myself thinking ‘Ugh, I have to open up Maya just to move the pivot on this object and re-export, why can’t I just move the pivot in-engine?’ … Not only in Unity but in other engines as well.
I’m glad you’ve addressed this and I’d love to see it work with objects at any rotation. GJ!
I’m not exactly sure what you’re trying to accomplish here or if it’s even a good idea (what happens if you update the asset? won’t the mesh be reimported and your new pivot lost?), but I noticed this note:
→ make sure you always use .sharedMesh and not .mesh
→ if you need a volatile mesh, set its hideFlags to DontSave or HideAndDontSave (I used this to distort a mesh in the editor without modifying the actual asset).
Don’t know if these tips apply in your case but well…
Hey Benoit,
I think your second advice is quite relevant; however my concern is, if you set a mesh’s flag to HideAndDontSave, the changes made will have disappeared the next time that scene is loaded, while the intent is to keep the new pivot position of the mesh.
Regarding the first advice, I believe the reason I used .mesh instead of .sharedMesh was to avoid the modification of asset files and to create a duplicate of the mesh to make the changes on.
What we’re trying to accomplish here is give Unity users a means to change the position of the pivots of their meshes, for which there really is no other solution. Moving the pivot elsewhere can help when trying to rotate or place the mesh in a certain way. There are several (old) posts in the forums about this.
I appreciate you taking the time to look into this. Let me know if you have additional advice.
Yeah but that’s the thing, if I understand correctly you’re moving the pivot of a mesh instance, that is an instance of an object containing a mesh (MeshFilter) in a scene… I don’t really see the point! Is it even persisted if you save/close/reopen the scene? If so, then you’re essentially making a copy of the mesh in each scene it’s sitting on, thus duplicating data, increasing your file size, losing asset connexion if the mesh is reimported… either I’m missing something or you’re paving the way for shooting yourself in the foot!
IMO, moving the pivot should be done at import-time… and, really, should be placed correctly in your modeling package to begin with! I know it’s super easy to do in Maya for example, while C4D is a bitch about it but it’s still doable.
Except if your workflow is such that you’d like a different pivot in your modeler than in Unity… but what I don’t see is why you’d want to move the pivot on a per-scene basis. You should move it at import-time (for the mesh asset itself, the sharedMesh), and after it’s just a normal mesh.
Side-note: kudos for posting on LinkedIn, if not for that I’d have never stumbled upon your blog !
Your problem struck me as interesting so I gave it a go… see package attached.
Menu Editor > Change mesh pivot wizard, select the mesh whose pivot you want to change, enter an offset, apply: the mesh is reimported with the new pivot. Every instance of this mesh will be affected. It’s just a proof-of-concept, no rotation etc.
The flow is a bit convoluted, as often with postprocessors especially when you need to pass data to them and have it persisted, but with some more work it could probably be made rather straightforward for the user.
You’ll probably never be able to just move the pivot on-the-fly in a scene though, but as I explained before I don’t think it’s a good idea to begin with. It would be interesting to try and make this and EditorWindow instead of a wizard, see if you could show a preview of the mesh with a gizmo to move the pivot visually…
This doesn’t work with planes. I tried setting the Y scale of the mesh to >0 but it still returns NaN. I also tried changing the scales of the bocx collider but this didn’t work either.