Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Coding error - does not denote a valid type

Discussion in 'Scripting' started by Hachoumi, Nov 25, 2015.

  1. Hachoumi

    Hachoumi

    Joined:
    Nov 24, 2015
    Posts:
    18
    so im making a script for motion blur for when my camera gets near an object.
    this is my code:
    Code (csharp):
    1.  #pragma strict
    2. private var mBlur : MotionBlur;
    3. function Start ()
    4. {
    5.     mBlur = GameObject.Find("Main Camera").GetComponent(MotionBlur);
    6.     mBlur.enabled = false;
    7. }
    8.  
    9. function OnTriggerEnter(Col : Collider)
    10. {
    11.     if(Col.tag == "Player")
    12.     {
    13.         mBlur.enabled = true;
    14.     }
    15. }
    16.  
    17. function OnTriggerExit (Col : Collider)
    18. {
    19.     if(Col.tag == "Player")
    20.     {
    21.         mBlur.enabled = false;
    22.     }
    23.  
    24. }
    and i get this error:
    Assets/MBlurTrigger.js(2,21): BCE0018: The name 'MotionBlur' does not denote a valid type ('not found').
     
    Last edited: Nov 25, 2015
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    First: use [code ]code tags [/code]
    It means that there's not a script named MotionBlur as far as the compiler knows at that time.

    Most obviously: Is there a script called MotionBlur in the project?

    I am assuming this refers to the Standard Assets MotionBlur script, which is C# - that's probably your problem. C# and JS can only see each other in specific situations. In this case, try putting MotionBlur inside a folder named Plugins. Scripts in Plugins folders are compiled first, and then are available to all scripts in the normal compilation process.

    Alternate solution: code in C# instead.
     
    Kurt-Dekker and Kiwasi like this.
  3. Hachoumi

    Hachoumi

    Joined:
    Nov 24, 2015
    Posts:
    18
    any idea how I can change that to c#? i dont really use c#
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    If you're going to change coding languages, you want to do so for your whole project, not just this one script. In that case, I recommend checking out some of Unity's coding tutorials - they're all C# based, and very good.
     
  5. Hachoumi

    Hachoumi

    Joined:
    Nov 24, 2015
    Posts:
    18
    I cannot find the plugin folder in Unity, is it under assets or?
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Assets/Plugins. You'll have to create it.

    This page lists all the special folder names, and what they do.
     
  7. Honorsoft

    Honorsoft

    Joined:
    Oct 31, 2016
    Posts:
    81
    It's 2018 now and I ran in to the same problem, "The name 'MotionBlur' does not denote a valid type ('not found')". There is another method to fix this (something some new javascript users seem to not be aware of) so I'll mention it because it will come in handy if you are using both C# AND JS scripts in your project. That is javascript's version of "using", which is "import". So, I was able to fix my MotionBlur error by adding this line of code to the top of the javascript (under #pragma strict):
    Code (CSharp):
    1. import UnityStandardAssets.ImageEffects;
    One other problem people might have is that Unity has deprecated the old ImageEffects, and now recommend the new Post-Processing Stack. Anyways, StarManta was right, you can move scripts to the Standard Assets folder to get them to work. I had the same error for the CharacterMotor.js ("The name 'CharacterMotor' does not denote a valid type"), which I was able to fix by putting the CharacterMotor.js in the Standard Assets folder.