0
\$\begingroup\$

I'd like to ask a case when developing a game using Unity.

There are many UI elements in the game.

These UI elements normally disappear from scenes when the purpose is achieved.

However, the Destroy or SetActive methods provided by Unity greatly affect game objects and sometimes lead to errors, especially when using coroutines, causing stability problems.

When making and using UI, is it standard and stable to use Alpha values of the UI's Image/panel component or Text component to make it disappear or appear?

Or is it standard and stable to use the SetActive function, passing true or false?

\$\endgroup\$
7
  • \$\begingroup\$ If Destroy or SetActive are leading to errors, you have written your code wrong, or made an error in your scene setup. API methods don't throw errors randomly — they obey a specific contract, and if you use them out of contract leading to unwanted behaviour, that's your error, and something you can fix. If you'd like help fixing those root problems, edit your question to document the steps to create a Minimal Complete Verifiable Example of one specific problem you've encountered when trying to use one of these methods. \$\endgroup\$
    – DMGregory
    Commented Jul 10, 2023 at 1:33
  • \$\begingroup\$ thanks to reply, I know my design's problem. I tried to fix it but failed. The error was nullreception. I Initialized my variables, but using setActive or OnEnable() there is always error occured \$\endgroup\$ Commented Jul 10, 2023 at 2:01
  • \$\begingroup\$ You mean a Null Reference Exception. We have lots of Q&A about addressing those errors. They're not inherent to the use of Destroy, but a result of using it under the wrong mental model. If you edit your question to show us what you did, there's a good chance we can show you how to fix it. \$\endgroup\$
    – DMGregory
    Commented Jul 10, 2023 at 2:45
  • \$\begingroup\$ It was an incredibly minor problem. I succeeded in resolving it, and after rebuilding it, we confirmed that the problem was resolved. Thank you for your help. It just gecomponentInchild problem ;( \$\endgroup\$ Commented Jul 10, 2023 at 5:34
  • \$\begingroup\$ If you've solved your problem, would you like to post your solution as an Answer, or delete this question? \$\endgroup\$
    – DMGregory
    Commented Jul 10, 2023 at 10:17

1 Answer 1

0
\$\begingroup\$

DMGregory's comment is very useful thanks

If Destroy or SetActive are leading to errors, you have written your code wrong, or made an error in your scene setup. API methods don't throw errors randomly — they obey a specific contract, and if you use them out of contract leading to unwanted behaviour, that's your error, and something you can fix. If you'd like help fixing those root problems, edit your question to document the steps to create a Minimal Complete Verifiable Example of one specific problem you've encountered when trying to use one of these methods

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This answer would be more useful if you showed how you applied this advice to solve your problem. \$\endgroup\$
    – DMGregory
    Commented Jul 17, 2023 at 1:09
  • \$\begingroup\$ I will do that next time. thanks \$\endgroup\$ Commented Jul 21, 2023 at 8:17
  • \$\begingroup\$ I recommend doing it this time, or your post may attract downvotes for not being very useful. \$\endgroup\$
    – DMGregory
    Commented Jul 21, 2023 at 10:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .