Why can't I use "material.diffuseTexture.uScale" property?

Hi I’m new to babylon.js and I’m trying the official tutorial.

I’m testing this(https://playground.babylonjs.com/#20OAV9#25) in my local environment, but as I mentioned in the title, I got errors like “Property ‘uScale’ does not exist on type ‘BaseTexture’. Did you mean ‘scale’?” for these parts:

mat1.diffuseTexture.uScale = 2;
mat1.diffuseTexture.vScale = 4;
// ...
mat2.diffuseTexture.uOffset = 0.25;
mat2.diffuseTexture.vOffset = 0.5;

Actually, I’ve received the same errors before.
What makes them?

I’d like your help please!

1 Like

Hey. This is not telling much. In theory this should work. We will probably need more info to figure it out. Can you share your code somehow? How are you defining textures and materials in your local environment. Maybe even version of Babylon.

If you look at the properties of BaseTexture though. There is indeed no uScale and vScale, but why you end up with BaseTexture is the question :smiley:

2 Likes

material.diffuseTexture is of type BaseTexture, and I can only assume you have made the right decision and are using typescript :slight_smile: Which is the main issue here (or better - it is the difference between the playground and your code).

The properties are there, since you have defined the diffuseTexture yourself), but typescript doesn’t recognize them.

What you can do is change the uScale of the texture you have created and not of the assigned diffuseTexture. something like this:

const texture = new Texture(....)
texture.uScale - 2

mat1.diffuseTexture = texture;

Thank you all for your reply very much.
I tried it like RaananW showed and it fixed the issue!

Are you saying that in typescript, there is no such thing as uScale property for diffuseTexture?

typescript is type safe. it means that if you don’t case and we define that a certain variable is of a certain type, this is the type the property will be checked against.

Gosh, what a sentence… sorry.

material.diffuseTexture is a BaseTexture.
The Texture you have created is of type Texture, which extends BaseTexture.
Texture has uScale, BaseTexture does not.
Type-safety-wise, material.diffuseTexture does not have uScale. But if you set it to be of type Texture, the original class can have uScale set, since it is of the right type.

I think I understand!
Thank you for explaining it in detail, it really helped me. :smile:

2 Likes