Can't Change the Sprite Actor at Runtime

Hello,

I have a function (for changing sprite, getting the sprites from a custom array (several, 10 different sets) and assigning them to Asset ID array).

Which I’m calling on a click of UMG Button.

Both print logs are working and returning the desired result.
But the sprite isn’t changing at run time (Play in Editor Window) but as soon as i escape the PIE and get back to view port, the sprites gets set to the last array on flip and the sprites are set to the scale of 1 (what I defined was 0.2).

The Sprite (which are Blueprints with sprite actor component (inherited)) are set to movable. (I tried it with setting them to static and stationary as well.)

Button is to check the function, I’ll be calling the function in a separate logic at defined time, not on click

1 Like

I can only see get mobility pin node in the blueprint :confused:

And got no idea how will i approach material offset with my array?

I’ll try making flipbook first (I got a basic idea to set it up), and if doesn’t give me the desired result I’ll try to make the material instance(haven’t worked with them that much, but let’s see).

About the c++ class, I don’t wanna mess with it and break my blueprint project. (it happened several times in the past, just adding a blank c++ class , so i can enable a third party plugin).

And Thank you for your help again :slight_smile:

Back again <3. Did you try to set the SpriteComponent to static and back to moveable in your code after SetSprite? (not on your components detail panel) Because that should work. It feels kinda hacky though and I’m not sure if that’s the “right way” to do it.

It would be great if you could add if that’s for a character or just some background stuff, because for the last one you could pack your sprites into a sprite sheet and offset the material itself instead of changing the whole material.

You won’t use an array, you will use a material with a texture that has all your sprites. You can make a flipbook inside Unreal if you have your sprites already there, but that way you have set the time inside your flipbook animation and stop it to get one of your 10 sprites. So, I would recommend using the flipbook node in your material and use an MID and change the time in your blueprint.

About the mobility thing, it’s only possbile in C++, here is an instruction if you by any chance got the knowledge.

1 Like

Got the sprite to change at runtime by setting the mobility in begin play, sprite color is working too. I’m using UE5, not sure if this is already exposed in previous versions.