# Failed to set media texture to a media texture which is from "Construct object from class"

**URL:** <https://forums.unrealengine.com/t/failed-to-set-media-texture-to-a-media-texture-which-is-from-construct-object-from-class/401551>\
**Category:** Asset Creation\
**Tags:** unreal-engine, construction-script, question\
**Created:** [August 12, 2017, 3:28am UTC](https://forums.unrealengine.com/t/failed-to-set-media-texture-to-a-media-texture-which-is-from-construct-object-from-class/401551 "2017-08-12T03:28:12Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![anonymous\_user\_a13fea89](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a13fea89](https://forums.unrealengine.com/u/anonymous_user_a13fea89)\
**Post date:** [February 28, 2021, 5:24pm UTC](https://forums.unrealengine.com/t/failed-to-set-media-texture-to-a-media-texture-which-is-from-construct-object-from-class/401551/13 "2021-02-28T17:24:03Z")

</div>

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:

```
UFUNCTION(BlueprintCallable, Category = "Modiverse")
	static void UpdateMediaTexture(UMediaTexture* mediaTexture)
	{
		mediaTexture->UpdateResource();
	}

```

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!!

Hope this helps someone out!

---

_[View the full topic](https://forums.unrealengine.com/t/failed-to-set-media-texture-to-a-media-texture-which-is-from-construct-object-from-class/401551)._
