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
1
Question by LvKA95 · Nov 16, 2020 at 11:30 AM · unityeditorerror buildplayer settingsusing

Little problem with PlayerSetting Editor Error...

Hi, today I'm here to talk about a problem with my script (I don't speak English well I'm using google translate, I hope you understand what I write ...)

I'll explain the problem that I currently have and that I can't solve (my knowledge in C ++ is low, what little I know I learned from video tutorials).

I am creating a game for android and at the moment I have created a menu with various settings (graphic, audio, display etc etc).

I've for a week now, been trying to figure out how to use PlayerSettings.muteOtherAudioSources = true

The script works correctly when I run the game in the PC but when I compile the APK the unity console gives me these 4 errors


  1. Assets/-Script/InterfacciaUI/ImpostazioniUI.cs(201,31): error CS0103: The name `PlayerSettings' does not exist in the current context

  2. Error building Player because scripts had compiler errors

  3. Build completed with a result of 'Failed' UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)

  4. UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x00242] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:194 at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:97 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)


Inside the ImpostazioniUI script I entered using UnityEditor; The error line of code is simply this

 if(mutaaudiofuorigioco==1) {PlayerSettings.muteOtherAudioSources=true;}

Looking for solutions on the internet I have tried various solutions and it seems that I will have to use another script via the Editor folder.

But now I have another problem, I would like to access the script functions inside the Editor folder, what can I do? Or if there is another way, how can I get PlayerSettings.muteOtherAudioSources to work on android; Is it possible or should I let it go?

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

1 Reply

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

Answer by jackmw94 · Nov 16, 2020 at 01:19 PM

The good news is that this is only 1 error.

PlayerSettings is part of the UnityEditor library, which means you can't use it or modify it within build code. PlayerSettings is a configuration so you should just be able to go Edit-> Project Settings then click the 'Player' option, click the tab for the platform you're building for and check mute other audio sources there. Then save the project. Now you shouldn't need to alter that value in code and removing it will mean your project can build.

Alternatively, if you HAVE to modify it in code (e.g. if it's within a build script), then you'll have to wrap any calls to PlayerSettings inside #if UNITY_EDITOR defines.

 #if UNITY_EDITOR
     if(mutaaudiofuorigioco==1) {PlayerSettings.muteOtherAudioSources=true;}
 #endif


and to prevent the UnityEditor library being included in your build, wrap the 'using' directive in editor only defines too at the top of the ImpostazioniUI script:

 #if UNITY_EDITOR
 using UnityEditor;
 #endif


But know that this will then ONLY be called within the editor before building and NOT on the build itself. If you're adding this as a setting the user can change then I don't think this will work.

Hope this has helped, let me know if you need any more information! :)

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 LvKA95 · Nov 16, 2020 at 06:56 PM 0
Share

hi jack, thank you so much for the reply!

I've tried and now it works!

I wanted to use PlayerSetting settings as an option that the user could disable / enable but in the final build I can't use it so...

$$anonymous$$y goal was to create a setting that turns off the app sound when you return to the home screen of the device (or just keep the game in the background).

I haven't checked if there are any features that can make the game understand when you keep it in the background, I hope so.

I will try to search if there is a simpler and more effective solution, thanks again for the detailed answer! :D

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

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

CommandInvokationFailure: Gradle build failed 2020 0 Answers

Unity Folders -1 Answers

i get an error when the host shots the client in Unet 0 Answers

Cant build my Game! UnityEditor Namespace not found? 2 Answers

Unity 2017 is not working. 2 Answers


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