Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Display a random video on an object

I am trying to display a random video on a plane object.

So far I am only able to display a specific video on a plane object at any given time: alt text

alt text

I could really use the help.

Product Version: UE 4.16
capture.png (53.5 kB)
t.png (185.9 kB)
more ▼

asked Feb 13 '18 at 04:09 PM in Blueprint Scripting

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You should be able to pick a random video to play if you add a MediaSource variable to your Blueprint and change it to an Array. Then on BeginPlay you can use a Random Integer in Range node to randomly select the index of a video from that array, then pass that video into the MediaPlayer. Here's an example of the node setup:

Node setup

Inside your array of sources, you just need to add each media source you want to have a chance of playing and one will be picked at random when the game starts.

Edit: be sure to check that there is at least one video in the list before calling Open Source. If you overlook this (as I did) and pass in an empty array, you will probably crash.

I hope this helps!

more ▼

answered Feb 14 '18 at 02:33 AM

avatar image

417 3 6 10

avatar image iSonastro Feb 14 '18 at 02:35 PM

Thanks my good guy, it works perfectly! One more question I have is if I could make it so after one video is done player, it will randomly select another video to play.

avatar image Chromarict Feb 16 '18 at 03:53 AM

You can use the MediaPlayer's On End Reached event for this. When you select the MediaPlayer variable in your Blueprint, you can click the big green plus next to the On End Reached event at the bottom of the Details panel.

MediaPlayer events

Once you click this, it will add that event to the Event Graph. I'd recommend moving the nodes from my main post into a function rather than copying it over. Then you can hook that function into the event and it'll look a little something like this:

On End Reached event

With this current setup, it will randomly select any video in the list, so it can replay previous ones, including the one that just finished. If you wanted to avoid this, you could add code to the random video function that removes the selected index so it won't be played again. Also, I added a check to make sure the list isn't empty because currently you run the risk of trying to get a non-existent video, which isn't a good idea. Here's the updated function:

Play Random Video

Even if you don't add the code to remove played videos, you should add the check to make sure there's at least one video in the list before you try playing one. If you don't, you could end up with an index out of bounds error, resulting in a crash. Sorry for overlooking that in my original post.

avatar image iSonastro Feb 16 '18 at 05:03 PM

Thanks so much, you really helped me out.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question