Reflected materials on reflected scene graph mesh components are incorrectly initialized

Summary

Reflected materials on reflected mesh components (scene graph) cannot be casted to the expted material subclass.

Please select what you are reporting on:

Unreal Editor for Fortnite

What Type of Bug are you experiencing?

Other

Steps to Reproduce

  • Create a custom material like m_custom_material (with at least one parameter) and a custom mesh like sm_custom_mesh.

  • Configure the material slot of the mesh to be m_custom_material.

  • Compile verse in a SG project to reflect them.
  • Create a custom component like the following:
using { /UnrealEngine.com/Temporary/SceneGraph }
using { /Verse.org/Simulation }

vz_test_reflected_material_component := class<final_super>(component) {
  OnBeginSimulation<override>(): void = {
    (super:)OnBeginSimulation()

    if (MeshComponent := Entity.GetComponent[mesh_component]) {
      if (ReflectedMeshComponent := sm_custom_mesh[MeshComponent]) {
        Print(ToDiagnostic(ReflectedMeshComponent.CustomMaterial))
        if (CustomMaterial := m_custom_material[ReflectedMeshComponent.CustomMaterial]) {
          Print("Material can be casted")
        } else {
          Print("Material can NOT be casted")
          Print("Overriding the material manually")
          set ReflectedMeshComponent.CustomMaterial = m_custom_material {}
        }
        Print(ToDiagnostic(ReflectedMeshComponent.CustomMaterial))
      } else {
        Print("Wrong mesh component")
      }
    }
  }
}
  • Add an entity to the scene that uses the custom mesh and add the custom component to it.

  • Run the simulation.

Here are the logs:

Assets_material /...-c1ab874f1c0b/vz_experiments_LevelInstance_3.vz_experiments:PersistentLevel.LevelEntity.LevelEntity.Entity.experiment_6-sm_custom_mesh_0.__verse_0x793F222D_CustomMaterial ❌UNEXPECTED
Material can NOT be casted ❌UNEXPECTED
Overriding the material manually
experiment_6-m_custom_material /...-c1ab874f1c0b/vz_experiments_LevelInstance_3.vz_experiments:PersistentLevel.LevelEntity.LevelEntity.experiment_6-m_custom_material_2147482645

Expected Result

The cast should succeed.

Observed Result

The cast should not fail.

Platform(s)

UEFN (v34.00)

Can confirm:
image

For context I force this error:

SpriteMaterial:=Materials.MI_PlayerSprite[SpriteMesh.SpriteSlot] or Err("Player Sprite Material Retrieval Failed")

FORT-870997 has been added to our ‘To Do’ list. Someone’s been assigned this task.

Hi, just wanted to give a quick update on this issue. We have some legacy code that reflects the material for the assigned default material slot. As a result, the default material does not know which subtype it is referencing when pointing at the default material (although it does work for any subsequently assigned materials).

I have a fix, but it fundamentally requires a restructuring of a significantly large part of the way we map UEFN assets to verse. It’s a WIP and we will get it resolved asap, but just wanted to let you know it may be a few months before this is fixed due to the significant size of the codebase we have to reconsider (although this will also help with several other bugs, so it is something we need to do asap). Apologies for the inconvenience.

2 Likes

Thank you for the update, however this is a good and bad news at the same time. The beta release of Scene Graph seems to be around the corner and this issue is very frustrating. I have applied a workaround everywhere I need it, but for a released experience this will likely create hiccups of different sorts. For example in my case I will have to swap / programmatically re-initialize materials on hundreds of mesh components. I’m not sure if this could also affect PSO pre-caching in some sort (not an expert on that bit). However I suspect that I’ll run into some frame drops, temporary or repeating (I already one frame drop on mobile device that I can 100% reproduce when I update the material parameter of a re-initialized material).