I’ve made a main menu widget and added a “Image” in which I want to play a random video whenever the user goes to the main menu. My problem is that I dont know how to make it switch videos randomly. I know how to set one video as a background, but not how to make it pick a random one. Is there a way to do this? My guess was to create a texture with multiple Texture sample and then in make it randomly output a Texture sample as final output. But I can’t find a randomizer inside of the texture, and I want the background video to change whenever the user comes back to the main menu too.
Would appreciate any help,
Thank you
What are you using specifically to set your video? Media, a gif, something else? My first thought would be to do something like finding a random int in range then set a “video” that corresponds to that int, but that depends on how you have your menu set up and may not be useful.
Any additional specifics you provide may go a long way in solving your problem.
I have mp4 videos. And I use a “Image” as background in the menu. It worked for a single video. But I can’t figure out the code I need to randomize the videos, and where.
Can you share the blueprints that you have so far? In the meantime, check out this non-Epic affiliated tutorial that seems to be what you are looking for:
This will also call the “OpenSource” event that I have in a specific “MenuGameMode” that is used whenever my menu pops up. This event is used to open source of the video. Notice that all arrays are built up respectively, meaning that for example, “video_1” (Media Player) is on index 0, then “video_1” (Material) will also be on index 0.
The important part here is just the Open Source node, the rest is optional*.
*I use the Rewind, Play, and Close nodes to have more control over the video, so that I can choose when to start, stop, restart the video.
(Here you have some more info about how to set up your textures and variables if done as me:)
After you created a “media player” of your video, set it to “play on open” (this might not be needed). then use “media texture” for each video and create a material from it. Set the “material domain” of the texture to “User Interface”. It should look something like this:
Then Inside your widget create “Wallpaper Texture” (array) in which you put all your materials (materials created from media texture), and promote the randomized index to a variable (we’ll need it later). Then go to your specific game mode for the menu and create a “Wallpaper” (array) for your file media sources, and a “MainMainMenuMedia” (array) for your media players. Change the variable names as you like of course, but that should be it already.