FastScriptReload icon indicating copy to clipboard operation
FastScriptReload copied to clipboard

When added field is removed in play-session it'll start throwing exceptions and will stop additional-values from rendering in editor

Open handzlikchris opened this issue 2 years ago • 8 comments

handzlikchris avatar Apr 04 '23 16:04 handzlikchris

I can't reproduce this. Is this still relevant? My test case: Original:

using UnityEngine;
using UnityEngine.InputSystem;

public class Test : MonoBehaviour {
    void Update() {
        if (Keyboard.current.kKey.wasPressedThisFrame) {
            Debug.Log("Pressed {key}");
        }
    }
}

Added field:

using UnityEngine;
using UnityEngine.InputSystem;

public class Test : MonoBehaviour {
    [SerializeField] string key = "W";

    void Update() {
        if (Keyboard.current.kKey.wasPressedThisFrame) {
            Debug.Log($"Pressed {key}");
        }
    }
}

FSR generated:

using UnityEngine;
using UnityEngine.InputSystem;

public class Test__Patched_: MonoBehaviour {
    /* [SerializeField] string key = "W"; */ //Auto-excluded to prevent exceptions - see docs

    void Update() {
        if (Keyboard.current.kKey.wasPressedThisFrame) {
            Debug.Log($"Pressed {FastScriptReload.Scripts.Runtime.TemporaryNewFieldValues.ResolvePatchedObject<Test__Patched_>(this).key}");
        }
    }

private static global::System.Collections.Generic.Dictionary<string, global::System.Func<object>> __Patched_NewFieldNameToInitialValueFn = new global::System.Collections.Generic.Dictionary<string, global::System.Func<object>>
{
    ["key"] = () => "W",
};


private static global::System.Collections.Generic.Dictionary<string, global::System.Func<object>> __Patched_NewFieldsToGetTypeFnDictionaryFieldName = new global::System.Collections.Generic.Dictionary<string, global::System.Func<object>>
{
    ["key"] = () => typeof(string),
};

}

Removed field - reverted back to original, there were on issues. FSR generated:

using UnityEngine;
using UnityEngine.InputSystem;

public class Test__Patched_: MonoBehaviour {
    void Update() {
        if (Keyboard.current.kKey.wasPressedThisFrame) {
            Debug.Log("Pressed {key}");
        }
    }

private static global::System.Collections.Generic.Dictionary<string, global::System.Func<object>> __Patched_NewFieldNameToInitialValueFn = new global::System.Collections.Generic.Dictionary<string, global::System.Func<object>>
{
};


private static global::System.Collections.Generic.Dictionary<string, global::System.Func<object>> __Patched_NewFieldsToGetTypeFnDictionaryFieldName = new global::System.Collections.Generic.Dictionary<string, global::System.Func<object>>
{
};

}

RunninglVlan avatar Jan 04 '25 21:01 RunninglVlan

BTW, this serialize field isn't visible in Inspector. Do I need to do something else for it to appear?

new fields will only show in editor if they were already used at least once

Added field is used in the method

RunninglVlan avatar Jan 04 '25 21:01 RunninglVlan

Could be that issue was sorted but that ticket was not updated (can't remember looking into it though)

I'll have a peek tomorror / early next week.

Was that method called after FSR reload? This part is quite dynamic and it'll be able to render once code actually executed.

Ie adding it to method that did not yet run after reload won't cause it to show.

Is demo example working for you?

handzlikchris avatar Jan 05 '25 13:01 handzlikchris

@RunninglVlan Alright - I think this one will still be relevant but there's bigger issue where rendering of new fields is broken (#154). Without fixing it we won't be able to repro.

Btw - thanks for support on patreon, appreciate that!

handzlikchris avatar Jan 06 '25 16:01 handzlikchris

Is it possible to make issues depend on one another on GitHub?

RunninglVlan avatar Jan 06 '25 16:01 RunninglVlan

Is this issue only about SerializeFields? Because I tried with normal fields and couldn't reproduce it either way.

RunninglVlan avatar Jan 06 '25 16:01 RunninglVlan

Not sure, but when you add link it'll show in the other.

It's both, newly added fields won't render right now

handzlikchris avatar Jan 06 '25 17:01 handzlikchris

Is it possible to make issues depend on one another on GitHub?

You can copy the link in a comment, github will relate them. If by depend you mean a "subtask" then I think there are tools for that as well.

Also this menu exist on OP (maybe only to contributors though) Image

builder-main avatar Mar 04 '25 19:03 builder-main