Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
Remove RectTransform from GameObject via Script

I have a GameObject with a RectTransform that I would like to remove via script. In other words, I want to replace the RectTransform with a regular Transform in the inspector using a script.

In the inspector, you can simply click the RectTransform dropdown and select Remove Component from there and the RectTransform is replaced with Transform. Of course this only works if there are no Components that rely on the RectTransform directly.

enter image description here

enter image description here

If I try this approach with a script like: Destroy(GetComponent<RectTransform>()) I get an error stating:

Can't destroy RectTransform component of 'MyGameObject'. If you want to destroy the game object, please call 'Destroy' on the game object instead. Destroying the RectTransform component is not allowed.

Of course, this is somewhat expected, since you can't remove a transform from a gameObject. In the case where I am trying to get back the old Transform component however, this behavior is undesirable.

So my question is: is there a way to replace the current RectTransform with a simple Transform component via script, and how is this done?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can't delete a conversion.Alternatively, create an empty object and move the entire hierarchy located on that object there. You can simply change the parent of the first child and align the local position, or implement a more complex system, depending on what you need it for.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda