Almost a year later this still is an issue. Looks like the created texture is not properly instantiated with “construct from class” on a construction script. If you set the variable to public and open it from the properties pane on the main viewport, you can see it’s not working. Then if you change any property inside the asset, like checking sRGB, it gets rendered.
UE 4.20.2 - running into the same issue: when using “Construct media texture” in blueprint - just a white screen is rendered. Trying to set all variables (SRGB, Clear Color, autoclear…) as presented in Content Browser for my working texture does not help. This is how I tried to create my media texture.
When just setting “Tex2use” to a media texture created in Content Browser texture, it works fine. Rest of BP code unchanged.
With UE4 4.20.2 : I did also run into a “white screen” when doing the “Construct Media Texture” in the Actor Blueprint code at BeginPlay. It works for me, if doing the “Construct Media Texture” in the Construction Script (as you obviously also did), but ONLY this construction.
Then at BeginPlay in Event Graph, doing the all other stuff:
Construct Media Player
Create Dynamic Material Instance
Set Texture parameter value to assign the texture to the material
Set media player to the material texture
Set media Player to the Media Sound Component
Run “Open URL” on Media Player to stream an MP4 URL (contained in string)
I sent a bug report in for it, with a project that shows the issue. I boiled it down to the bare basics, showing that if you pass in the texture that’s an asset, it shows, but if you create it, it doesn’t. Everything else (creating the media player, setting it’s source, opening it, etc.) is done dynamically. Here’s the project if you want to see it:
For those who are still looking for an answer to this I found a way to make it work:
- Create the media player and the media texture in the construction script of the actor.
- In BeginPlay you can set the media player reference in the media texture and it should work fine.
- For the material you can create it in the construction script and set the texture parameter there too, it should work if you do this in begin play too.
I played the video on another event so I don’t know if you can play it right away, maybe wait a few frames would be a good idea especially if a lot of things are already hapening on begin play.
Good catch about creating the media texture in the construction script. That’s the only thing that needs creation there, as I have everything else created dynamically in the project I made for the bug report (UE-89272).
I have found then you need to use either OpenSourceWithLatent or bind to OnMediaOpened (in your BeginPlay) if you want to do any Play/Pause/etc. stuff right after opening it. Otherwise, it’s not finished opening yet.
I spawn multiple media players in my Sandbox game so I think I’ve figured this one out; it seems that when you set the source of the media player, the media texture seems to loose it’s link to the media player; so when it’s trying to read data it simple has no “media player” to read data / frames from.
The solution is to force an update of the underlying media texture resource, but it requires some C++.
In your xxx.build.cs make sure you have the “MediaAsset” dependancy:
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
...
"MediaAssets"
});
Then in a C++ actor, include the header at the top…
#include "MediaTexture.h"
Then inside your C++ object (the header file) - create a static function to do the magic:
Then BP process was similar as mentioned; create media texture in constructor script (not sure this is still required) and then in my “spawn” event I create media player, dynamic material (with a texture parameter set to the media texture), get my 3D plane and set it’s material to this dynamic material instance and finally I “Set Media Player” on the media texture (pointing it at the media player)… I then “Open URL” and after that call the above “UpdateMediaTexture” BP node to fix it… Seems to work fine in editor and published game!!