Why am I getting this Error?

Hello, all. I am working with some code to change text depending on a variable.
Here is the code.

  if (phase === 1) {
            this.cstxt1.element.text = 'Hello, I am Leanana';
            this.cstxt2.element.text = 'Hi, what do you do?';
            //  this.cstxt2.setPosition(-237.094,-69.018,-403.066);
            this.cstxt3.element.text = 'Do you have any tasks for me?';

        if (phase === 2) {
            this.cstxt1.element.text = 'I am a fighter piolot.';
            this.cstxt2.element.text = 'Do you have any tasks for me?';
            //  this.cstxt2.setPosition(-237.094,-69.018,-403.066);
            this.cstxt3.element.text = 'What do you fly?';

        if (phase === 3) {
            this.cstxt1.element.text = 'I fly a cruiser.';
            this.cstxt2.element.text = 'Have a good day!';
            //  this.cstxt2.setPosition(-237.094,-69.018,-403.066);
            this.cstxt3.element.text = 'Do you have any tasks for me??';

        if (phase === 4) {
            this.cstxt1.element.size = 0.01;
            this.cstxt1.element.text = 'Yes! I left a battery at one of the gaurd towers.';
            this.cstxt2.element.text = 'Decline';
            //  this.cstxt2.setPosition(-237.094,-69.018,-403.066);
            this.cstxt3.element.text = 'Accept';
            decision = 1;


Lines 2, 9, and 24 don’t give me an issue, but line 16 does. This is the error: [cutscenemagager.js?id=176180148&branchId=d716681b-5f85-49bf-bd12-abd5d124b363:109]: Cannot read properties of null (reading ‘element’)

TypeError: Cannot read properties of null (reading ‘element’)
at Cutscenemagager.update (https://launch.playcanvas.com/api/assets/files/Scripts/UI/cutscenemagager.js?id=176180148&branchId=d716681b-5f85-49bf-bd12-abd5d124b363:109:25)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:107514:22)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:107548:15)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:108308:52)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:108326:11)
at ComponentSystemRegistry.fire (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:1668:21)
at AppBase.update (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:71874:19)
at https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:72927:20
Another weird thing that happens is that line runs, but then line 16 doesn’t run. I have tried to fix it, but I have not been able to. Any ideas?

Oh, and this only happens on the first run-through of the cutscene (What I am making) On the second run-through it works perfectly.

Hi @Codeknight999!

It seems like the entity of this.cstxt1 doesn’t exist or is not defined correctly at the point where line 16 is executed.

I suggest to check if the entity is available in the editor and if it is defined correctly by script.

@Albertos, I checked and it is defined as a script attribute and it is spelled correctly, but it still seems to not work. It is only for that one line. All the other lines that have similar code work properly.

What is a phase? So what is the different between phase 2 and phase 3?

If you share a link of your project and tell me how I can reproduce the issue, I can take a look.

Phase is a variable. PlayCanvas 3D HTML5 Game Engine scene Decay. Turn around, there is a capsule with the text “Leanana”. Walk forward, and when the UI appears, hit 1 until the issue occurs. Thanks.

I did a quick check and I don’t see anything wrong in the setup.

How can I see it working, so I can compare both setups?

Here is a vid. Feel free to tell me if I missed anything you need.

I have seen the error, but I was unable to find the cause.

I like to know where I can check the editor setup of this.

If you can access this: PlayCanvas | HTML5 Game Engine that is the full script. In there, it is lines 95,102 and 117. Line 109 is the one giving me the error.

I mean when do you execute the other lines? How can I reproduce the working part to check the differences?

If you try this, and when the cutscene opens, press 1 on the keyboard, each time you press it phase increases by 1, and it progresses the cutscene.