Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Celsius · Oct 03, 2013 at 05:15 AM · instantiatebooleans

Better way to do this? Instatiate or simply turn on and off?

Hi,

I have a simply question, regarding which would be the 'better way' to do this particular thing..

I have a very simply room with 4 paintings.

Initially they are blank.

Underneath the paintings, they have a button(labelled 1 - 4) as per each painting.

When you press a button, the corresponding painting is no longer blank but has a 2d picture. When pressing the button again, the corresponding painting goes blank.

eg;

b b b b 1 2 3 4

b= blank numbers=buttons

press 1, b becomes P (a painting with a picture) press 1 again, P becomes B(a painting blank again)

in doing so, a person can have 4 blank paintings, 4 pictured paintings or a mix.

Now my question is:

Is it better to instantiate a picture painting(2d object) and destroy it as per button commands OR is it better to simply put a boolean.(If true, picture is shown, if false pciture is hidden and thus you only see a blank background).

Paintings are in 2d.

I will likely have a lot of paintings etc so I was wondering would it be better to therefore instatiate or because it is 2d, it won't matter if they are all 'there' but hidden and I use the boolean true/false method.

Thanks in advance.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadoX · Oct 03, 2013 at 06:35 AM 0
Share

Not talking from experience, but the general idea that I usually seem to find is that it's always a bad idea to constantly instantiate and destroy objects during gamePlay. $$anonymous$$ost people usually seem to suggest that you should instantiate all objects at the start of a scene and either hide/show them or create some form of pooling for those objects assu$$anonymous$$g that you know how much of those objects you'll need.

I guess you could check this yourself if you have Unity Pro by creating a simple test scene and comparing the memory usage (and whatever else the profiler spits out) between a scene where you instantiate and destroy objects constantly VS a object pool.

avatar image Fattie · Oct 03, 2013 at 07:49 AM 0
Share

You know (A) performance is irrelevant at this stage. (B) the only "correct, sensible" way to do it in this situation is using SetActive. (C) it is not necessary to test in the profiler exactly as you suspected Shadow, it is like 18 billion times slower to instantiate.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Fattie · Oct 03, 2013 at 07:48 AM

The answer is to simply turn it on and off - it's that simple.

Just use SetActive(true) and SetActive(false).

OK?

There are other strategies, like you will see people turning on and off the renderer. But really at your stage just use SetActive.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Celsius · Oct 03, 2013 at 12:54 PM 0
Share

Hi, currently I am turning renderer on and off, since it's It's merely a bunch of 2d images.

And thankyou for notifying me to 'tick' an answer. I'll do so from now on.

edit: sorry to be a bother, but I do not see a 'tick' option?

avatar image Fattie · Oct 03, 2013 at 01:19 PM 0
Share

the renderer works well - enjoy!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Destroying Instantiated Obect Problem 1 Answer

Checking if object intersects? 1 Answer

Instantiate problem. 3 Answers

How to instantiate once when boolean changes 1 Answer

Instantiate rotation question. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges