- Home /
The question is answered, right answer was accepted
Accessing FilterMode possible on a 2D sprite?
renderer.material.mainTexture.filterMode = FilterMode.Bilinear;
is what the reference says I should do to access the filter mode of my sprite.
I have tried
var renderer1 : Renderer;
and
var renderer1 : SpriteRenderer;
but both give me the error "Object reference not set to an instance of an object."
I've used Debug.Log to try and find the problem and it seems to be the "filterMode" part that it has a problem with. I've attached the whole code below if that helps. The script is attached to my sprite and the sprite renderer is enabled.
#pragma strict
public var renderer1 : SpriteRenderer;
function Start ()
{
renderer1 = GetComponent("Renderer");
}
function Update ()
{
if (Input.GetKey (KeyCode.UpArrow))
{
Debug.Log( renderer1);
Debug.Log( renderer1.material) ;
Debug.Log( renderer1.material.mainTexture) ;
Debug.Log( renderer1.material.mainTexture.filterMode); // Throws error.
}
}
The error appears when I press the Up arrow. This won't actually be in my game, I just want to figure out how to access the filterMode.
Thanks very much!
Romano
Answer by Romano · Feb 27, 2014 at 08:09 AM
SUCCESS. It's a bit different for 2D sprites it seems.
Instead of this:
spriteRenderer1.material.mainTexture.filterMode = FilterMode.Bilinear;
Use this:
spriteRenderer1.sprite.texture.filterMode = FilterMode.Bilinear;
nice find, i mtrying to set mine to point filter, but it literally has no affect, any ideas?