Search Issue Tracker

By Design

Votes

1

Found in

2019.4

2019.4.13f1

2021.1

Issue ID

1293888

Regression

No

Assemblies not being reloaded when reimporting C# script asset

Scripting

-

How to reproduce:
1. Open the user's project "AOP_REV2.zip"
2. Open "SampleScene" Scene
3. Click on "GameObject" in the Hierarchy window
4. In the Inspector window right-click on "Expensive Operation Sample" Script
5. Click on "XD238" and look at the console
6. In Project window -> Assets -> ITnnovative -> AOP -> Sample
7. Edit "ExpensiveOperationSample" Script edit 21'st line and change Debug.Log message to something else
8. Save and Reimport asset
9. Repeat 3 - 5 steps
10. Repeat 3 - 9 steps again

Expected results: Console logs out a message that the user changed to in the 7th step
Actual results: Console logs out the "JUST XD" again

Reproducible with: 2019.4.16f1, 2020.1.16f1, 2020.2.0b14, 2021.1.0a8
Couldn't test with: 2018.4.30f1 (Couldn't downgrade to a working project)

Note: New message appears after the first script change, but not after later ones

  1. Resolution Note:

    The project in question is modifying the compiled assembly, by weaving the assemblies. This is non-support workflow.

    By removing all the weaving code, the problem is resolved and changing the message will correctly reload the code.

    Looking at the code here is my take away:
    You are creating a circular dependency inside Assembly-CSharp. You can see that by using a tool like DotPeek or any assembly decompiler.
    Because of this, the original Assembly-CSharp will not be unloaded.
    Cecil might be causing problems for you here. As you are calling ImportReference. When doing this on a type in the very same assembly you are calling from, you are screwed.

Comments (1)

  1. TitanumIchigo

    Dec 03, 2020 10:19

    Reproduced on 2019.4.15f1. It requires project to be recompiled before changing variable to attach additional Weaving methods to Unity Editor AssemblyReloadEvents. Then after changing it's not updating text anymore. May be heavily affected by PC configuration.

    I think it's because Unity wants to reload assembly while it's still being modified by external code, which locks the file, so it cannot be used by other software incl. Unity.

    Tested on: R9 3900X OC 4.8GHz, RTX 2070 Super Gigabyte Gaming OC (default), 64GB DDR4 3600MHz CL17, NVMe SSD 3GBps.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.