Author Topic: SubText sorting layer and order follows parent text?  (Read 1982 times)

robertwahler

  • Newbie
  • *
  • Posts: 9
SubText sorting layer and order follows parent text?
« on: November 20, 2016, 09:20:44 AM »
We are animating text objects and need to change sortingLayerID and sortingOrder at runtime to do so. Does it make sense to add something like this to manage sortingLayerID and sortingOrder "AFTER" the subText objects have been created?  Currently, there is no easy way to manage sorting of subTexts after a text object has been created.

Code: [Select]
...
set {
  m_renderer.sortingOrder = value;
  for (int i = 1; i < m_textInfo.materialCount; i++)
    m_subTextObjects[i].renderer.sortingOrder = value;
}
...

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5682
Re: SubText sorting layer and order follows parent text?
« Reply #1 on: November 20, 2016, 12:11:02 PM »
We are animating text objects and need to change sortingLayerID and sortingOrder at runtime to do so. Does it make sense to add something like this to manage sortingLayerID and sortingOrder "AFTER" the subText objects have been created?  Currently, there is no easy way to manage sorting of subTexts after a text object has been created.

Code: [Select]
...
set {
  m_renderer.sortingOrder = value;
  for (int i = 1; i < m_textInfo.materialCount; i++)
    m_subTextObjects[i].renderer.sortingOrder = value;
}
...

On the normal TMP component which uses the Mesh Renderer, the Sorting Layer ID and Sorting Order can be controlled in the Inspector Panel on the Sub Text objects themselves. Via scripting, these can be set by accessing the m_subTextObjects.renderer of the sub objects.

I can certainly look at adding an addition property to the TMP object to manage this. Can you provide more insight and example of how you would be using this functionality?

robertwahler

  • Newbie
  • *
  • Posts: 9
Re: SubText sorting layer and order follows parent text?
« Reply #2 on: November 21, 2016, 05:55:15 AM »
Thanks for the help. I should have mentioned that the subTextObjects are generated only at runtime, automatically, due to our use (I think) of a fallback font for missing symbol characters.

We need to control the sorting layer/order at runtime because that is the only way we've been able to control the drawing order. We have a single prefab we instance multiple times with a mesh on the bottom and sprites and text mesh pro components on top. Think Scrabble board pieces with Text Mesh Pro used for the letters. When you pick up a Scrabble piece and move it over another another Scrabble piece we want to only see the piece that is higher in the z-order.  It seems changing the layer/sort order is the only way to do this?   This works but it we need for subTextObjects to follow the parent text object layer and sort order, thus my patch of the the sortingOrder setter.  Is there a better way to accomplish what we want? Thanks again.

ADanto6840

  • Newbie
  • *
  • Posts: 3
Re: SubText sorting layer and order follows parent text?
« Reply #3 on: October 17, 2018, 01:26:37 PM »
I know that this is old, but as far as I can tell it's still a problem & is one we just ran into after upgrading TMP on our project. 

It's especially a pain now that we've upgraded from using the source (within project) commercial version to the Unity-provided UPM version which means its another hoop-jump to even edit the source to "fix" this issue.

As is, the only way (AFAICT) to get at the child renderers (during runtime) is some ugly GetComponentInChildren<T> calls or editing the TMP source, which just makes things difficult in the future when upgrading.

We have the same requirements as the OP, and we want the child meshes to "follow" the parent meshes (or whatever we set on the main TMP object itself) around at all times.  In our case, we'd even be OK with a static default, but as-is it seems that literally the only way to even get at those renderers during runtime is to GetComponent<T> or edit TMP source.  Neither are preferred attack vectors on this, especially when the main TMP object presumably already has the refs, they're just not exposed...