Material Tween error

Hi, I am following the instructions to tween a material (Color) )here (Using the Tween library | Learn PlayCanvas ) but when I run the exact code on my project I get:

Cannot read properties of undefined (reading ‘material’)
TypeError: Cannot read properties of undefined (reading ‘material’)

My code is:

var color = new pc.Color(255, 0, 0);
        var material = this.entity.render.material;
        .to(new pc.Color(1, 1, 1), 1.0, pc.Linear)
        .on('update', function () {
            material.diffuse = color;

But the whole thing is in my update loop because I want to run the tween only when within distance to the player. Maybe this is the issue. I am completely lost with this. Cheers

Your error seems to indicate that you either don’t have a render component / material on your entity.

Have you added a render component and a material on the entity that has this script in your scene?

1 Like

It would also be great to post a small public project for the community to have a closer look your issue too :slight_smile:

1 Like