Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
This question was closed Oct 07, 2016 at 04:26 PM by tanoshimi for the following reason:

The question is answered, right answer was accepted

avatar image
-4
Question by Zitoox · Oct 05, 2016 at 02:31 AM · script erroreffectfixunderwater

Underwater effect error

You know... I was having some problems with making an underwater effect recently, so i chose to just copy and paste a script that i have found in the SUPPOSEDLY Unity's official Wikia. (Also, you guys should get that thing offline, the last time it's scripts were updated was a long time ago).

I've tried to update, i tried to change some things, but i still get two errors: alt text

This is the script:

 using UnityEngine;
 using System.Collections;
 
 public class UnderWater : MonoBehaviour
 {
 
     //This script enables underwater effects. Attach to main camera.
 
     //Define variable
     public int underwaterLevel = 7;
 
     //The scene's default fog settings
     private bool defaultFog = RenderSettings.fog;
     private Color defaultFogColor = RenderSettings.fogColor;
     private float defaultFogDensity = RenderSettings.fogDensity;
     private Material defaultSkybox = RenderSettings.skybox;
     private Material noSkybox;
 
     void Start()
     {
         //Set the background color
         GetComponent<Camera>().backgroundColor = new Color(0, 0.4f, 0.7f, 1);
 
     }
 
     void Update()
     {
         if (transform.position.y < underwaterLevel)
         {
             RenderSettings.fogColor = defaultFogColor;
             RenderSettings.fog = true;
             RenderSettings.fogColor = new Color(0, 0.4f, 0.7f, 0.6f);
             RenderSettings.fogDensity = 0.04f;
             RenderSettings.skybox = noSkybox;
         }
         else
         {
             RenderSettings.fog = defaultFog;
             
             RenderSettings.fogDensity = defaultFogDensity;
             RenderSettings.skybox = defaultSkybox;
         }
     }
 }


Can anyone help me to identify and fix those bugs? Also, if one of you happen to be a WebMaster of the website, you could also edit the page. Here's the original outdated link: Unity Wikia

Ah, and before someone ask "Oh, it is so simple, why didn't you follow the instructions?" Because i am so tired that i can't even think right AND because these lines actually doesn't exist... You know.... seriously.

wtf.png (27.1 kB)
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

  • Sort: 
avatar image
0
Best Answer

Answer by Namey5 · Oct 05, 2016 at 03:13 AM

Have you tried moving the initialization stuff inside a function rather than having it with the variable declaration?

 //The scene's default fog settings
 private bool defaultFog;
 private Color defaultFogColor;
 private float defaultFogDensity;
 private Material defaultSkybox;
 private Material noSkybox;
 
 void Awake ()
 {
     defaultFog = RenderSettings.fog;
     defaultFogColor = RenderSettings.fogColor;
     defaultFogDensity = RenderSettings.fogDensity;
     defaultSkybox = RenderSettings.skybox;
 }
Comment
Add comment · Show 15 · 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 Zitoox · Oct 05, 2016 at 03:22 AM 0
Share

Actually, i already tried that, but i am going to give it a try. $$anonymous$$aybe it works.

avatar image Zitoox · Oct 05, 2016 at 11:18 PM 0
Share

@Namey5 Nope, didn't worked. I've tried with void start too.

avatar image Bonfire-Boy Zitoox · Oct 05, 2016 at 11:52 PM 0
Share

That's odd because the error message seems pretty clear. Have you removed the initialisations from the variable declarations as well as adding them to the Awake function, as Namey5 showed?

avatar image Bonfire-Boy Bonfire-Boy · Oct 06, 2016 at 12:11 AM 1
Share

Yes, I read your comment. If you search this site for get_fog you'll find several people with the exact same problem, for whom the fix was exactly as Namey5 said. So it is worth pursuing, especially as the error message is telling you what the issue is.

The lines in the error do exist, they're just not lines that you wrote. The error is telling you that when the instance is being created by its constructor ( UnderWater.ctor() ), you're trying to access something that you can't access at that point (because the constructor is run on the loading thread and many of the Unity functions can only be run on the main thread).

It would appear that some or all of those RenderSettings.fog* properties involve a call to RenderSettings.get_fog(), and that's one of those things that you can only use on the main thread.

If the code used to work and now doesn't, I suspect it's because things like RenderSettings.fog used to be simple static variables, but in more recent versions of Unity they are now properties that need to invoke this get_fog method.

Is it possible that Unity isn't loading your script changes for some reason?

Show more comments
avatar image Namey5 Zitoox · Oct 06, 2016 at 12:04 AM 0
Share

It is indeed strange. There's no real reason why it would work, but just as a failsafe perhaps try it in the update function.

 private bool start = true;
 
 void Update ()
 {
     if (start) {
         defaultFog = RenderSettings.fog;
         defaultFogColor = RenderSettings.fogColor;
         defaultFogDensity = RenderSettings.fogDensity;
         defaultSkybox = RenderSettings.skybox;
         start = false;
     }
 ...
avatar image Zitoox · Oct 06, 2016 at 10:31 PM 0
Share

@Namey5 wtf... It still doesn't work. Could you post the entire script changed? I think i am missing something in here. Also, did you tested it?

avatar image Zitoox Zitoox · Oct 06, 2016 at 11:10 PM 0
Share

Never$$anonymous$$d, i WAS missing something! I was replacing a thing that i wasn't supposed to.

avatar image Namey5 Zitoox · Oct 07, 2016 at 06:20 AM 1
Share

What do you mean by 'need an answer'? Is it fixed?

Show more comments
avatar image Zitoox · Oct 07, 2016 at 03:26 PM -2
Share

Yes, i already said that 3 times. You guys should practice a little of "expression"...

Anyway, could you make this comment an answer? While you do this i am going to negativate that guy for giving me a $$anonymous$$us!!

avatar image tanoshimi Zitoox · Oct 07, 2016 at 04:26 PM 2
Share

I understand that English may not be your first language, but you should know that your comments do come across as both rude and difficult to understand: you have repeatedly stated that the problem is fixed but also that you still need an answer. When others who are trying to help you have asked for clarification, you might want to be more tolerant in your explanation.

avatar image Namey5 Zitoox · Oct 08, 2016 at 06:08 AM 0
Share

All we are trying to do is help you and your issue. I understand that it may be frustrating if someone does not understand your point, but please be patient when asked for clarification as it may be you who is co$$anonymous$$g across as vague.

Follow this Question

Answers Answers and Comments

57 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

Related Questions

Underwater Effect? 3 Answers

Does any one knows how to replicate this effect in unity 3d ? 0 Answers

Unity2D: Game Mechanic 0 Answers

Want to do an on-hit effect for a trail renderer in 2D 0 Answers

wind effect on high poly mesh,adding wind to 3d object 0 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