keenanwoodall / Deform

A fully-featured deformer system for Unity that lets you stack effects to animate models in real-time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LatticeDeformer behaves differently in edit mode compared to play mode

msklywenn opened this issue · comments

Describe the bug
In edit mode, if a mesh is instantiated and a latticedeformer added to it, it's scale will be changed to match the size of the bounds of the mesh. Doing the same thing in play mode will keep its original scale.

To Reproduce
Make some editor script that instantiates a mesh with bounds different from (1,1,1) and adds a latticedeformer to it, and run it both in edit and play mode. Something like:

            var road = Instantiate(RoadPrefab, transform);
            var deformable = road.gameObject.AddComponent<Deform.Deformable>();
            var lattice = road.gameObject.AddComponent<Deform.LatticeDeformer>();
            deformable.AddDeformer(lattice);
            lattice.GenerateControlPoints(new Vector3Int(2, 2, 2));
            lattice.SetControlPoint(0, 0, 0, ...

Expected behavior
Scale doesn't change when script is run in edit mode.

  • OS: Windows 10
  • Unity: 2021.2.10
  • Deform version: 1.2.1

Additional context
The scale change is done when LatticeDeformer.Reset() is called by the editor. I think the problem is that this function should not be named Reset as it is one of Unity's "special functions". Renaming Reset to Reconstruct fixes the issue. I'm also not sure why Reset/Reconstruct changes the scale of the mesh, it doesn't seem needed for LatticeDeformer to work.