Dynamic material instance doesn't work on mobile

This bug only appears in C++ project.

I want create Dynamic material instance in MyActor. I did this in OnConstruction method and all works in editor preview, but when I launch level on mobile dynamic material instance return null.

Sample project creates two dynamic instances, first in C++, second in blueprint. Next in Tick method instances are cheked if are valid. In editor both return true, but on mobile only blueprint one return true.

Sample project

Hello Matii,

Thank you for reporting this issue. I’ve reproduced this and entered a bug report for it under the number UE-32691. The oddest thing is that it seems that the same behavior occurs in PIE (Selected Viewport) as what happens on a mobile device, although the other PIE modes such as Mobile Preview and Standalone Game don’t experience the problem.

I’ll be sure to let you know whenever any updates are made to the report or if we need any further information. Have a nice day!

Hello Matii,

After speaking with a developer about this issue, it appears that this is working as intended. The OnConstruct function for this blueprint would not be called in this particular situation. OnConstruct is called when the asset is edited in the editor or spawned dynamically. Since this is an actor that is already placed in the level, OnConstruct never gets called for it in the packaged game. To get around this, you can have another asset or the map itself spawn the asset on BeginPlay which will cause the OnConstruct function to be run.

It isn’t working as intended. One of devs mentioned here Construction script equivalent, OnConstruction is same as ConstructionScript in Blueprint.

I did more tests with dynamic material and here are results:

Blueprint:

  • BeginPlay - works
  • ConstructionScript - works

C++

  • BeginPlay - works
  • OnConstruction - doesn’t works

As you can see C++ equivalent isn’t working.

Hello Matii,

If you refer to the original post in that forum thread, the user is asking for a C++ alternative to blueprint’s Construction Script for use in the editor. In this situation, OnConstruct does act in the exact same way as the blueprint’s Construction Script. This does not mean that it works that way at runtime however. Nothing related to construction in C++ is going to be called at runtime unless something is dynamically spawned.