Clone entity and run animation again and again

Yes, that’s it @eproasim! I was getting the same result in my sample project first, but after cloning the material, it works as expected. Thanks!

I updated my sample project.

https://playcanvas.com/project/862089/overview/tween

I was passing it to tell the code which entity’s texture I wanted to update.

I shall see this

Thanks a lot this worked

I also had another query , when you play my code, you will see when the card exits , due to some reason exit animation is only applied to the player card and dealer card just disappears.
Can you please help me debug this?

A post was merged into an existing topic: Keep my application running in background

Can you give me a reaction on this first please, to be able to understand your logic?

So my current mesh has 2 materials I only wish to update one side thats why I set address as one , as my materials are in my _meshInstances and inside there is an array of materials which I update, with the help of code in your test project you shared I was able to implement what i needed in my project, I cloned my materials and updated the material which i wanted to apply texture to , since you are a part of the project you can check it
thanks for the help

Also now as we know playcanvas stops all animations in background. My whole script works on the base of my api and the response that comes from that API, but now i face a major problem.
Let’s say now, I get a response==true from my api, but at this point user has minimized/switched tabs/just loading the game. At these time I already have a true from my api and animation triggers when the screen loads again or when person comes back to the tab.
Now what I want is that, if the person comes in at a particular time then it should load in the place where it is supposed to , for example if I have got a response from the api prior to user coming only then I wish to show the card already placed in its respective box and not show the animation.
For this I thought I can use states like in react, so I wanted to know if there is any method to do this in playcanvas where I can manage the game as if it is running in background and load it in the same status when the user comes in

I moved this to another topic because it’s not related here.

Okay , but can you please respond there too?

It’s a little difficult to debug your project because I’m unable to see where you get the information from, for statements like below.

if (data?.result[0]?.runners[0].card[0]) {
    // your code
}

It can takes a long time before a new card is given, probably a part of the game I don’t inderstand, but I saw the long waiting time is controlled with the statements this.state, this.state2 and this.state3. But how you use that states looks again a little odd to me. For example the statement below.

if (this.state === true) {
    // your code
}
else{
    this.state = true;
}

How does your statement here make sense?

I only respond to topics or posts if I can say something meaningful about it. My knowledge is limited.

So what I am doing here is

data?.result[0]?.runners[0].card[0]

from here I get the same data for X amount of time, and it is repetetive, so I have set the states, so basically when I first get a response I set a state as true, hence animation runs, and in the if I set state as false , thus even though I get the same value it will not go inside the if loop, and as soon as I get a empty value of card it sets the sate as true again and once new card comes in , it will begin the whole animation for next card

Alright, I think I kind of get it. Wouldn’t the on complete function of the tween be a better alternative? I use it in my example project. You can also create a timer.

I have set my animations in different scripts for a reason , thats because I want to trigger those different keyframes at any point of time
now since I am using oncomplete function , will it trigger my next script as sooon as the animation in this script is done?
Like I want to understand how it onComplete() a better option than my current code and how will it work for a queue of animations in different scripts

You talk about animations, but I only see one or two tweens that rotate and change the position of the card, like I do in my example project. So do you mean the tweens or do you mean animations that I didn’t see yet?

lets go with tweens, I am moving my object from one place to another

That’s right, please look at the manager script in my example project. There I use it to execute the addCard function when the tween is ready.

As an alternative you could use a timer.

// initialize function
this.timer = 0;
// update function
this.timer += dt;

// execute your function every 10 seconds
if (this.timer > 10) {
    this.timer = 0;
    // your function
}

Offcourse you can add more conditions to the statement, to prevent your function is executed when you don’t want it.

If your function is in another script, you could use events or reach the function like below.

otherEntity.script.scriptName.yourFunction();

Okay thank you