Author Topic: Transform reset on any cell/territory change  (Read 66 times)

nandusmasta

  • Newbie
  • *
  • Posts: 22
    • View Profile
Transform reset on any cell/territory change
« on: August 01, 2020, 06:24:05 AM »
Hey guys. I am having a problem with the Terrain Grid System, I am using it without any terrain, with a custom rotation and set as a child of one of my objects. The problem is that whenever I do a change, like even the color of a cell, the transform is reseted; it loses any custom rotation and parent settings. How can I avoid this? I am looking through the code to find where and why this happens, but I felt it'd be faster if any of you know where to look at least. Thanks in advance.

nandusmasta

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Transform reset on any cell/territory change
« Reply #1 on: August 01, 2020, 06:45:56 AM »
I ended up commenting the code below in the UpdateTerrainReference method of the TGSPrivate.cs class. So far nothing seems broken.

Code
if (transform.parent != null) {
transform.SetParent (null);
transform.localScale = new Vector3 (100, 100, 1);
transform.localRotation = Quaternion.Euler (0, 0, 0);
}

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5953
    • View Profile
Re: Transform reset on any cell/territory change
« Reply #2 on: August 02, 2020, 08:43:26 AM »
Hi, good catch.
That code ensures TGS remains an isolated gameobject when un-parenting it from terrain. As soon as the link with terrain parent is broken, there's no need to keep calling that code. This should be fixed in next update.
In your case, it's completely safe to uncomment those lines.
Regards

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5953
    • View Profile
Re: Transform reset on any cell/territory change
« Reply #3 on: August 02, 2020, 08:45:36 AM »
fyi, this is how the code looks like in our dev branch now:

Code
                if (transform.parent != null && transform.GetComponentInParent<Terrain>() != null) {
                    transform.SetParent(null);
                    transform.localScale = new Vector3(100, 100, 1);
                    transform.localRotation = Quaternion.Euler(0, 0, 0);
                }

nandusmasta

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Transform reset on any cell/territory change
« Reply #4 on: August 03, 2020, 08:39:08 AM »
fyi, this is how the code looks like in our dev branch now:

Code
                if (transform.parent != null && transform.GetComponentInParent<Terrain>() != null) {
                    transform.SetParent(null);
                    transform.localScale = new Vector3(100, 100, 1);
                    transform.localRotation = Quaternion.Euler(0, 0, 0);
                }

Great. That makes total sense. I will probably change my code to this, just in case some problem arises with a future update.