Nullreference when GameObject checking for itself

Hi!
I hawe a this line bellow on a script, that checks for the RawImage component of the gameobjeckt, that is attached to it. When this line runs, I get nullreference exception. I just wanted to set the texture of the sprite. It can’t be too hard, or it is?

this.GetComponent().texture = customTexture;,

That line is not valid code. There are two ways to call that method. One is by passing a generic type
argument (the ideal way)

GetComponent<MyComponentType>()

and the non generic way where you pass the type as a normal argument

GetComponent(typeof(MyComponentType))


What you have done is neither of those things. You shouldn’t even be able to get to the point where you are getting runtime errors. It shouldn’t compile.


But if it does then that will be why. It has no idea what component you are trying to get.


also using this is probably redundant