Bug with setMaterialParameter

  • Good day, I tried to use setMaterialParameter method to change some variables in prefab material, but this results with game freezing and locking OS completely, while logs are overfilled with these messages up to 2GB very quickly:

    Quote

    API: Cannot find game object 3655, adding to queue...

    API: Update prefab (MaterialParameterVector4) -> (DarkColor)

    Looks like the game falls into infinity cycle

  • That's weird :wat: The 1st line is quite normal, it happens if any component was changed before the prefab was fully loaded (usually there is a small delay until a prefab is fully loaded at the client), the 2nd line then indicates that the prefab was loaded and the material parameter was assigned... I couldn't reproduce it on my end unfortunately, so I'm wondering how this happened exactly :thinking:


    Did you change the material parameter for the prefab parent, or any child element?


    Do you mind sending me the prefab (or more precisely, the AssetBundle) and the code to change the material parameter, so I could try to reproduce the issue? ;)

  • I couldn't reproduce it on my end unfortunately

    After some code and log analysis I found that it happened when Prefab was not loaded from asset bundle (incorrect argument for loadFromAssetBundle) and setMaterialParameter was called for that prefab.


    When prefab is loaded correctly the bug is missing, but setMaterialParameter is not working for me. I'm trying to set color parameter, probably this is a reason

  • After some code and log analysis I found that it happened when Prefab was not loaded from asset bundle (incorrect argument for loadFromAssetBundle) and setMaterialParameter was called for that prefab.

    Oh, yes, I can confirm that this indeed results in an infinite cycle :wat: Thanks for letting me know, we will fix that with the next update!


    When prefab is loaded correctly the bug is missing, but setMaterialParameter is not working for me. I'm trying to set color parameter, probably this is a reason

    Hmm... that should basically work. Unfortunately the setMaterialParameter() method does not have an override which accepts a color object, but you could just use a Vector4f for that :)


    Also make sure to provide the correct property name (the "parameter" parameter^^). It you're using the default HDRP Lit shader, the main color property is "_BaseColor", for the default HDRP Unlit shader it's "_UnlitColor".

  • Also make sure to provide the correct property name

    Thank you, adding underlines worked, I just thought that using same name as property have in shader graph will be enough



    Another small thing that was probably not reported - any definitions that are provided by object.getDefinition() will be null in the world if it will be reloaded. They works fine only with first world loaded after game was launched

  • Thank you, adding underlines worked, I just thought that using same name as property have in shader graph will be enough

    Basically the "Reference" field of the Shader Graph property is the relevant name when accessing the material parameter - typically it begins with an underscore ^^


    Another small thing that was probably not reported - any definitions that are provided by object.getDefinition() will be null in the world if it will be reloaded. They works fine only with first world loaded after game was launched

    Thanks for letting me know! Apparently the definitions aren't reset properly... the game internally caches the "API definition" object upon first call, but that reference becomes invalid after reloading the API... we'll try to get this fixed for the next update ;)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!