Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

374
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda