Digital Native Studios

TextMeshPro => Support => Topic started by: Korindian on March 08, 2017, 06:01:03 PM

Title: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Korindian on March 08, 2017, 06:01:03 PM
Hi,

I didn't have this problem last night, so I'm guessing it happened after installing the latest Unity patch 5.5.2p2.

I'm loading an TMP_InputField GameObject via code into a canvas. After it is parented, I get the error:

Can't add a 'RectTransform' to the "InputField Input Caret" game object during Awake when a 'Transform' is already attached.
You probably need to add a 'RectTransform' to the "InputField Input Caret" game object in the editor.

I notice that the dynamically created InputField Input Caret GameObject (normally called TexteshPro - InputField Input Caret) gets a Transform component rather than a RectTransform when it is loaded via code. If the InputField GameObject already exists in the canvas before pressing play, the Input Caret GameObject correctly gets a RectTransform component.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 08, 2017, 06:19:38 PM
I am traveling until Friday and currently have a pretty bad internet connection which precludes me from installing Unity 5.5.2p2. I should be able to look into this over the weekend. Right now there are RectTransform issues with Unity 5.6 which have yet to get resolved so I am hoping these are not filtering down to Unity 5.5.2...

Unless you absolutely need to use Unity 5.5.2p2, I suggest you stick to Unity 5.5.2p1 which works fine.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on March 09, 2017, 11:45:52 PM
I was bitten by this as well, just noticed this error after having upgraded to 5.5.2p2 just a few days earlier.. I guess there's no workaround on TMPs end, looks like a bad Unity bug to me?  :-\
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 10, 2017, 06:42:11 AM
I was bitten by this as well, just noticed this error after having upgraded to 5.5.2p2 just a few days earlier.. I guess there's no workaround on TMPs end, looks like a bad Unity bug to me?  :-\

I tried Unity 5.5.2p2 and did't get the error so I might need a Report of this? Are you getting this error when loading the example scene with the Input Field and Scrollbar?
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: sevensails on March 10, 2017, 11:54:50 AM
I have the same problem. Just add a TextMeshPro Input Field and when Testing It the Bug Happens. I'm on Windows.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 10, 2017, 12:04:20 PM
I have the same problem. Just add a TextMeshPro Input Field and when Testing It the Bug Happens. I'm on Windows.

I just installed Unity 5.5.2p2 on the MacBook Pro which I use when traveling but I am not getting this error.

Can you provide the steps to reproduce the behavior?
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: sevensails on March 10, 2017, 03:28:47 PM
I think I know why you was not able to reproduce it.

Please, try keep the Parent GameObject where the Input Field Is Disabled and Activate it only in Runtime. It seems the problem only happens on this situation.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on March 11, 2017, 01:10:07 AM
Yes, it is definitely related to the fact that stuff is disabled on the scene and enabled at runtime.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 11, 2017, 10:55:47 AM
Yes, it is definitely related to the fact that stuff is disabled on the scene and enabled at runtime.

Good information. I got back around 1:00 AM last night but will be looking at this today and provide an update as soon as I have something.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 11, 2017, 04:02:49 PM
In Unity 5.5.2p2, the following now results in the following error: "Can't add a 'RectTransform' to the "New Child" game object during Awake when a 'Transform' is already attached."

Here is the scene hierarchy used to reproduce this behavior.

(http://i.imgur.com/9TJCSed.png)

Here is the script attached to this parent object.

Code: C#
  1. using UnityEngine;
  2.  
  3. public class SandBox_01 : MonoBehaviour {
  4.  
  5.    private GameObject m_ChildGameObject;
  6.  
  7.    private void Awake()
  8.    {
  9.        if (m_ChildGameObject == null)
  10.        {
  11.            m_ChildGameObject = new GameObject("New Child", typeof(RectTransform));
  12.  
  13.            m_ChildGameObject.transform.SetParent(this.transform);
  14.        }
  15.    }
  16. }
  17.  

Key to reproducing the issue is to have the parent object disabled when entering play mode and then enabling it afterwards.

So basically, adding a RectTransform to any object in Awake() at run time, will throw this error in Unity 5.5.2p2 and Unity 5.6. I am not sure of the implication of this new limitation but this seems like an issue to me.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on March 13, 2017, 12:21:43 AM
Can you raise an Unity bug about this, Stephan? Sounds like something they should fix.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 13, 2017, 12:51:37 AM
Can you raise an Unity bug about this, Stephan? Sounds like something they should fix.

I will be discussing this tomorrow with the lead on the UI team at Unity.

For certain, not being able to create a gameobject in Awake() and then add any Graphic component to it like an Image seems wrong to me.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on March 13, 2017, 12:56:30 AM
I will be discussing this tomorrow with the lead on the UI team at Unity.

For certain, not being able to create a gameobject in Awake() and then add any Graphic component to it like an Image seems wrong to me.

Great! Keep us posted.  :)
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: avee on March 14, 2017, 04:07:38 AM
We've managed to do a quick and dirty fix until the issue is properly resolved.

So we established that Unity, after the update to 5.5.2p2, forbids creation of gameobjects with RectTransform, if the object is instantiated at runtime.

Line 763 of TMP_InputField creates a GameObject named: transform.name + " Input Caret". Its default Transform was silently upgraded to RectTransform, but this is no longer possible.

 A way to fix it is to clone the object's parent which has a RectTransform and a RectMask2D component. Then destroy the RectMask2D component (which is not needed on the caret), destroy its children and rename it to input caret.
It's as if you needed a carton box, but instead of getting just the carton box, bought a box full of bananas, chuck all the bananas out and be happy to have the box you need.

This code below should replace the code from line 763 in TMP_InputField.cs:

Code: [Select]
GameObject go = Instantiate(m_TextComponent.transform.parent.gameObject, m_TextComponent.transform.parent);
                    Destroy(go.GetComponent<RectMask2D>());                   
                    int count = go.transform.childCount;
                    for (int i = count - 1; i >= 0; i--)
                    {
                        GameObject.Destroy(go.transform.GetChild(i).gameObject);
                    }

                    go.name = transform.name + " Input Caret";
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 16, 2017, 01:48:05 PM
Just heard from the Unity developer(s) responsible for this part of their code and they will be revising the handling of adding components like RectTransforms in Awake.

Long story short, I will be able to modify the current Caret object creation by simply using the following where the RectTransform is added as the object is created.

Code: C#
  1. GameObject go = new GameObject(transform.name + " Input Caret", typeof(RectTransform));
  2.  

Note: Creating a new object and then adding a RectTransform using AddComponent() will no longer be possible in Awake(). But as shown above, creating a new object and adding the RectTransform in that same function will still work in Awake(). This last part isn't really related to TMP but just good overall stuff to know in Unity.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on March 31, 2017, 01:21:37 AM
Just heard from the Unity developer(s) responsible for this part of their code and they will be revising the handling of adding components like RectTransforms in Awake.

Long story short, I will be able to modify the current Caret object creation by simply using the following where the RectTransform is added as the object is created.

Code: C#
  1. GameObject go = new GameObject(transform.name + " Input Caret", typeof(RectTransform));
  2.  

Note: Creating a new object and then adding a RectTransform using AddComponent() will no longer be possible in Awake(). But as shown above, creating a new object and adding the RectTransform in that same function will still work in Awake(). This last part isn't really related to TMP but just good overall stuff to know in Unity.

I noticed TMP beta 8 had been released, with separate version for 5.5 and 5.6. Does the b8 for 5.5 work around this Awake() / RectTransform issue? We're still stuck with 5.5.2p1 because of the issue.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on March 31, 2017, 01:52:33 AM
Just heard from the Unity developer(s) responsible for this part of their code and they will be revising the handling of adding components like RectTransforms in Awake.

Long story short, I will be able to modify the current Caret object creation by simply using the following where the RectTransform is added as the object is created.

Code: C#
  1. GameObject go = new GameObject(transform.name + " Input Caret", typeof(RectTransform));
  2.  

Note: Creating a new object and then adding a RectTransform using AddComponent() will no longer be possible in Awake(). But as shown above, creating a new object and adding the RectTransform in that same function will still work in Awake(). This last part isn't really related to TMP but just good overall stuff to know in Unity.

I noticed TMP beta 8 had been released, with separate version for 5.5 and 5.6. Does the b8 for 5.5 work around this Awake() / RectTransform issue? We're still stuck with 5.5.2p1 because of the issue.

Unity fixed this issue in the soon to be released Unity 5.6.0f3.

This should also be fixed in the next Unity 5.5 patch which will hopefully be available next week.

BTW: I am not certain this is the last tweak we will see on this. Right now, creating new GameObjects in Awake and adding a RectTransform afterwards still can result in issues which will trip up users and developers.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on March 31, 2017, 03:20:55 AM
Alright, thanks for the info. I'll wait for the next 5.5 patch, then.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on April 09, 2017, 10:57:22 PM
Anyone tested 5.5.3p1, if the problem still persists? I will test it myself today unless somebody reports that it isn't fixed yet..
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on April 10, 2017, 01:46:21 PM
Anyone tested 5.5.3p1, if the problem still persists? I will test it myself today unless somebody reports that it isn't fixed yet..

This issue is fixed in Unity 5.6 but it doesn't appear that it has been fixed in Unity 5.5.3p1 yet.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on April 10, 2017, 10:18:24 PM
This issue is fixed in Unity 5.6 but it doesn't appear that it has been fixed in Unity 5.5.3p1 yet.
Bummer! Thanks for replying though. Maybe next week? EDIT: Or this week, rather..
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: atraver on May 03, 2017, 08:31:53 AM
It looks like this functionality has not been added to 5.5.3p2, either. Stephen, do you have any info about whether or not it's going to land in the 5.5 branch, or is it just headed for 5.6 and 2017.1?

Fortunately, it looks as though avee's workaround does the job for now, but it's not really something I'd like to keep in my project.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on May 03, 2017, 11:31:59 AM
It looks like this functionality has not been added to 5.5.3p2, either. Stephen, do you have any info about whether or not it's going to land in the 5.5 branch, or is it just headed for 5.6 and 2017.1?

Fortunately, it looks as though avee's workaround does the job for now, but it's not really something I'd like to keep in my project.

Let me check when this is suppose to make it into 5.5.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on May 10, 2017, 10:38:46 PM
5.5.3p3 has a promising change:
(902580) - Editor: Fixed an issue that prevented the creation of GameObjects with a RectTransform component.

Do you know if that indeed solves this issue?
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: Stephan B. on May 11, 2017, 01:25:15 AM
5.5.3p3 has a promising change:
(902580) - Editor: Fixed an issue that prevented the creation of GameObjects with a RectTransform component.

Do you know if that indeed solves this issue?

I have not had a chance to test it but I know these issues are / have been worked on.
Title: Re: Input Caret GameObject having Transform instead of RectTransform on 5.5.2p2
Post by: mh114 on May 14, 2017, 11:14:22 PM
It seems that 5.5.3p3 solved the issue, finally.