Hi, I’d like to swap a sprite of crate that has its lid closed, to a lid that’s open. I’d also like to have a prompt saying Press E to open and when pressing E, it’ll swap the sprite.
Hey, how would I go about making it a variable? Do I do this in the level blueprint section? Also how can I then make the sprite have a prompt and then make it swap?
Please don’t make new answers, it makes things look messy and confuses others. Just create a new comment below my answer.
What you want to do is drag out your “sprite component” into the editor, then from the sprite component drag out and say “set sprite”. You will get the node you see above. From there, right click on the input “new sprite” pin and select “promote to variable”. Now you can change your sprite to whatever you make the “new sprite” variable equal to. You do this in the blueprint that contains the sprite. As for the last part of your question, you would need some sort of overlap event when the player is close or other event to create a widget that you add to the view port with your prompt. Then if it is a key press you would need to have some key input in a controller or player BP and a boolean connected to a branch node right after the input key to check if the bool is true or false to prevent swapping when the player is not allowed. Following the true execution you would then have this script above to actually swap sprites.
Hi, thank you very much for replying, however I don’t have the Set Sprite thing like in your screenshot, mine is different. I’ve also managed to trigger a sprite change, however it’s sized completely differently and makes a wall, with the original sprite intact.
Why aren’t you using the method I showed you if you want to change a sprite to another sprite? What you’re doing is saying:
- On overlap of the crate sprite
- Add a sprite with the same relative transform to the crate sprite
- Set this sprite to a crate sprite
So it looks like you’re just adding a crate sprite to another crate sprite
Hey,
I can’t get sprite component and my new sprite, it’s literally not coming up and it just says add new sprite.
Show me the BP of your crate sprite. I want to see the components tab.