Error CS0246: The type or namespace _____ could not be found. - What to type in MonoDevelop?

How do I fix the error in the title for the type or namespace of “GlowEffectThreshold_26”, “MotionBlurEdge” and “ColorCorrectionEffect”?

I know there’s something I need to type and save in the following coding but I don’t know what, please help:

using UnityEngine;
using System.Collections;
public class EffectController : MonoBehaviour
{
public Generate2DReflection generate2dReflection;
public GlowEffectThreshold_26 glowEffect;
public MotionBlurEdge motionBlur;
public ColorCorrectionEffect colorCorrection;

void Update()
{
if(QualitySettings.currentLevel < QualityLevel.Good)
{
if (generate2dReflection)
generate2dReflection.enabled = false;
if (glowEffect)
glowEffect.enabled = false;
if (motionBlur)
motionBlur.enabled = false;
if (colorCorrection)
colorCorrection.enabled = false;
}
else
{
if (generate2dReflection)
generate2dReflection.enabled = true;
if (glowEffect)
glowEffect.enabled = true;
if (motionBlur)
motionBlur.enabled = true;
if (colorCorrection)
colorCorrection.enabled = true;
}
}
}

Hm. This code does not make much sense. What is your intention with this?

Please use code tags to make your code more readable. Also, don’t summarize your error messages, but paste them exactly as they occur to better help people see your issues.

2 Likes

@Duugu Looks like he’s using a combination of quality settings and null-checking in order to activate or deactivate scripts. Not really complicated, or “doing it the wrong way” in itself, though it IS hard-to-read without code tags.

@Lynxication Of course, you should absolutely use [code ][/code ] tags, which I’m about to demonstrate. Also, doing this in Update makes no sense- you’re setting them to enabled/disabled every single frame for no reason. Whether they’re enabled or disabled should be set by the quality control in the options menu, where “saving” will call a function here to change the status of those scripts once.

Anyways, the way you fix your errors is likely by checking which namespaces each of these scripts uses. It’s likely that in the GlowEffectThreshold_26 script, for instance, there’s a line at the beginning that says:

namespace StandardAssets.Effects {

… or something to that effect. You need to either include that namespace at the top of this script with a:

using StandardAssets.Effects;

or by qualifying the type directly in the code by changing:

public GlowEffectThreshold_26 glowEffect;

to something like

public StandardAssets.Effects.GlowEffectThreshold_26 glowEffect;

Note that these are only examples, and that is NOT the namespace this script is in. You’ll need to check the effects scripts for their correct namespaces.

The alternatives are that you mispelled the class names or that the class names don’t match the script names for those classes, which can be a problem for Monobehaviour-derived classes.

1 Like

Thanks guys, it works now. :slight_smile:

There’s a useful shortcut for this, when you notice a class/namespace hasn’t been imported, move your text cursor to it and press ctrl + alt + space and the MonoDevelop intellisense should give you a suggestion of namespace you could import to fix it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}

c:\Users\Javier\Desktop\Unity\TUTORIAL\Assets\Scripts\Move.cs(7,7): Error CS0246: The type or namespace name ‘UnityEngine’ could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Move)

Error CS0246: No se pudo encontrar el tipo o nombre de espacio de nombres ‘MonoBehaviour’ (falta una directiva de uso o un referencia de ensamblaje?) (CS0246) (Mover)

I GET THESE ERRORS, CAN SOMEONE HELP ME.?