is it okay to mix Canvas objects (rectTransform) with regular game objects (transform), if those game objects have nothing to do with UI?

Viewed 324

I've ended up in a situation where I have a parent Canvas element for my game's battle system (to display health text, etc), and have a mixture of UI stuff and controllable game objects as it's children. So some of the objects have transform, and others have rectTransform.

Here's a small sample of my hierarchy:

https://i.imgur.com/Aa4wovx.png

  • The Parent BattleCanvas is a canvas object (rectTransform)
  • BattleEnemyObject and BattlePlayerObject are regular gameObjects (transform)
  • BattleObjects (a container for all instantiated objects) uses rectTransform,
  • But its child SnakePlayer is a regular gameObject (transform)

I'm beginning to realize how messy this is, but things seem to work fine so far. So my question is, is it okay to mix Canvas stuff (rectTransform) with regular game object stuff (transform), if those game objects have nothing to do with UI?

I guess I sort of have a lack of understanding of the difference between transform and rectTransform. Any advice here is appreciated!

1 Answers

Yes it is absolutely ok. RectTransform inherits from Transform. So all RectTransforms have all the functionality of a normal transform.

Many people change the canvases the render mode to World Space and then treat the RectTransform as a normal transform to space it in the world. There are some interesting effects like the one below that requires RectTransform to be used as a transform.

enter image description here

You can have multiple canvases with multiple render modes for some very interesting effects.

Related