# Cannot read property 'setTexture' of undefined

**URL:** <https://phaser.discourse.group/t/cannot-read-property-settexture-of-undefined/8825>\
**Category:** Phaser 3\
**Created:** [February 7, 2021, 9:49am UTC](https://phaser.discourse.group/t/cannot-read-property-settexture-of-undefined/8825 "2021-02-07T09:49:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chair](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@Chair](https://phaser.discourse.group/u/Chair)\
**Post date:** [February 7, 2021, 9:49am UTC](https://phaser.discourse.group/t/cannot-read-property-settexture-of-undefined/8825/1 "2021-02-07T09:49:43Z")

</div>

Hello,

I’m trying to change a sprite to another and I’m getting this weird error message: Cannot read property ‘setTexture’ of undefined

Here is the line of code triggering the error:  
`this.enemy1_display.setTexture(this.getEnemyString(displayed[0]));`

`getEnemyString()` returns a string which correlates with a sprite that I’ve already preloaded, and enemy1\_display is a sprite that I’ve created like this:  
`this.enemy1_display = this.physics.add.sprite(830, 90, "enemies1");`

This is strange because I’ve done a number of similar things already in the same file. A bit above, I use this line of code and it works perfectly  
`this.player.setTexture('ship1')`

I’ve also already used the ‘getEnemyString()’ method in a very similar way here:  
`var enemy = this.enemies1.create((x + 2) * (550 / 7) - 10, ((y + 2) * 50) - 35, this.getEnemyString(displayed[0]));`

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [February 7, 2021, 5:32pm UTC](https://phaser.discourse.group/t/cannot-read-property-settexture-of-undefined/8825/2 "2021-02-07T17:32:04Z")

</div>

> [@Chair](#):
>
> Cannot read property ‘setTexture’ of undefined

That means

```js
this.enemy1_display.setTexture(this.getEnemyString(displayed[0]));

```

is

```js
(undefined).setTexture(this.getEnemyString(displayed[0]));

```
