Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AmirSavand · Oct 27, 2017 at 01:29 PM · objectplatformspecific

Show object for a specific platform only.

I want to have an EXIT button but only for Windows build.


How to do it? and I don't want to hide it, I want it to not to be rendered at all.

Comment
Add comment · Show 8
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 Bonfire-Boy · Oct 27, 2017 at 01:39 PM 1
Share

I would detect the platform using either preprocessor directives or Application.platform, and then activate/deactivate the button's gameobject accordingly.

But I may be missing something.... what's the difference in your $$anonymous$$d between hiding it and not rendering it?

avatar image AmirSavand Bonfire-Boy · Oct 27, 2017 at 01:53 PM 0
Share

I meant, it's best practice not to render an object for a platform that should not be visible too.

About activating the object. If I don't activate an object, would it still be in the RA$$anonymous$$?

Or objects that are not activate, are not loaded?

@nyonge you can respond too.

avatar image nyonge AmirSavand · Oct 27, 2017 at 02:08 PM 1
Share

In short, yes, the object would still be in memory even if it's inactive, because it would've been loaded with the scene.

However, once it's loaded, if it's deactivated it'll have an incredibly small impact on your performance, so it likely wouldn't be an issue. Even loading would be $$anonymous$$iscule if it's just a simple button. You could have it deactivated by default, and only activate it if it's on Windows, which should work fine.

If you'd rather not load it at all, it cannot be in your scene at start. In that case, when you've detected that you're running Windows, you can use Resources.Load to add the object to your scene when necessary.

Show more comments
Show more comments
avatar image connorwforman · Oct 27, 2017 at 02:56 PM -1
Share

Platform discri$$anonymous$$ation. Interesting.

3 Replies

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

Answer by AmirSavand · Oct 27, 2017 at 04:18 PM

Best solution that takes the least RAM is to use Prefabs to add objects in the scene by platform condition.

Thanks to @nyonge and @Bonfire-Boy .

Comment
Add comment · 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
0

Answer by JonasAA · Oct 27, 2017 at 01:40 PM

 #if (UNITY_STANDALONE_WIN)
 // button logic
 #endif

https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

Comment
Add comment · Show 1 · 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 AmirSavand · Oct 27, 2017 at 01:51 PM 0
Share

Already answered like that.

avatar image
0

Answer by nyonge · Oct 27, 2017 at 01:43 PM

Platform-dependent compilation is your friend!

 #if UNITY_STANDALONE_WIN
 //do windows stuff
 #elif UNITY_STANDALONE_OSX
 //do apple osx stuff
 #else
 //do whatever else, presumably mobile or linux
 #endif

Hope that helps :)

Comment
Add comment · Show 3 · 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 AmirSavand · Oct 27, 2017 at 01:51 PM 0
Share

I know how to do it in code, but what about objects in editor?

avatar image nyonge AmirSavand · Oct 27, 2017 at 01:55 PM 0
Share

I'd create a script called ShowWindowsOnly, with something like this

 private void Start() {
 #if UNITY_STANDALONE_WIN
 //correct platform, do nothing
 #elif UNITY_EDITOR
 //show the button in the editor
 #else
 //it's another platform and not editor, disable object
 gameObject.SetActive(false);
 #endif
 }
avatar image AmirSavand nyonge · Oct 27, 2017 at 01:56 PM 0
Share

I'd do that too. can you read and respond the comments under my question? Thanks.

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

78 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 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 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 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 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

give a command to a specific instantiated object 2 Answers

moving an object with a specific speed 1 Answer

Unity Serializer Scene Only? 1 Answer

Click To Delete Specific Object 1 Answer

Trouble adding score when specific object is clicked. (C#) 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