Search Unity

Unable to reference custom image effect

Discussion in 'Scripting' started by BadSeedProductions, Sep 29, 2016.

  1. BadSeedProductions

    BadSeedProductions

    Joined:
    Dec 26, 2014
    Posts:
    144
    I purchased an image-effect asset yesterday and it did not come with any documentation. There is a function that needs to be called within the image effect script to play the image effect animation. However I can't reference it, if I try I get an error. Author is not responding... Any ideas? Thanks in advance!
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Unfortunately, you'll need to provide more info. If it's a component, you should be able to use GetComponent to get it and then if you hit . after, it should show you some options. There is also the possibility that it needs a namespace.

    So, lets say you do gameobject.GetComponent<ImageEffect>(), if the ImageEffect script comes up red and you wrote it correctly, you can right click on it. In Visual Studios, select the lightbulb and it should give you an option to add the namespace.
     
  3. BadSeedProductions

    BadSeedProductions

    Joined:
    Dec 26, 2014
    Posts:
    144
    Thanks Brathnann! I forget about that lightbulb sometimes! The image effect had a namespace called PostProcess. Vis Studio recommended that I link to it like so gameobject.GetComponent<PostProcess.ImageEffect>()

    Hopefully that does the trick!

    I have never written any image effects, and don't plan on it any time soon, but can anyone tell me why the image effect script starts with this namespace? Im not sure what this means, or the what it results in.

    Code (CSharp):
    1. namespace PostProcess
    2. {
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Yep. you can do that. You could also add using PostProcess; at the top with all the other using. That way you don't have to Add PostProcess before each ImageEffect.

    Basic idea of namespaces is to divide code. Think of it this way. If you write a class called ImageEffect and I write a class called ImageEffect and we stick it in the same project, the code wouldn't know which to use when we try to create an ImageEffect. So you might put yours under namespace BadSeedProductions and I would put mine under Brathnann. Then we can refer to them with BadSeedProductions.ImageEffect or Brathnann.ImageEffect to determine which one we wanted to use.

    The namespace itself has nothing to do with it being an imageeffect. You can namespace code that does all sorts of things.
     
    BadSeedProductions likes this.