[SOLVED] Script logic seems to be dependent on the entity hierarchy

Sorry, I’m not familiar with how you created the interval function, so I’m not sure why it’s not defined there either.

Maybe the topic below can help you.

Alternatively, you can use a tween to fade in and out your elements. (For this, you need to add the tween.js script to your project).

https://developer.playcanvas.com/en/tutorials/tweening/

Below example code from one of my own projects.

var FadeIn = pc.createScript('fadeIn');

FadeIn.prototype.initialize = function() {
	this.entity.enabled = true;

	this.elements = this.entity.findComponents("element");

	this.elements.forEach(function(element) {
		element.opacity = 0;
	}.bind(this));

	this.opacity = {value: 0};

	this.opacityTween = this.entity.tween(this.opacity).to({value: 1}, 3, pc.Linear).on('update', this.onFade, this);

    this.opacityTween.start();
};

FadeIn.prototype.onFade = function() {
	this.elements.forEach(function(element) {
		element.opacity = this.opacity.value;
	}.bind(this));

	if (this.opacity.value == 1) {
		this.app.timeScale = 0;
	}
};
1 Like