Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug StreamingAssets not (fully) updated in build

Discussion in 'Editor & General Support' started by jfrs20, Jul 27, 2023.

  1. jfrs20

    jfrs20

    Joined:
    Jul 8, 2020
    Posts:
    9
    Hi,

    I have a build script, that's called via menu from editor (Unity 2021.3.28f1):

    Code (CSharp):
    1.  [MenuItem("Build/Standalone build")]
    2.     static void Standalone()
    3.     {
    4.         InitPlayerSettings();
    5.         EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows);
    6.         buildClient(false);
    7.     }
    "InitPlayerSettings" saves build date and git repository information in "UnityEngine.Application.streamingAssetsPath" as "version.txt" and "repo.txt", respectively.
    Then it calls (maybe not necessary? seems, it doesn't work here as intended)
    AssetDatabase.Refresh()


    "buildClient" builds development (true) or release (false) via
    BuildPipeline.BuildPlayer(buildPlayerOptions)


    Both version.txt and repo.txt are always rewritten in project StreamingAssets. But sometimes, only version.txt is updated in the build directory, while repo.txt isn't (it stays as existing version if any - it's copied, however, if there is no repo.txt in previous build).

    Any idea why it behaves that way? AFAICT this is a bug.

    It seems, with "BuildOptions.CleanBuildCache" it works as it should, but this is not a real solution because build takes unnecessarily longer.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
  3. jfrs20

    jfrs20

    Joined:
    Jul 8, 2020
    Posts:
    9
    Hi,

    thank you for this idea. Unfortunately nothing changed.

    However, after time consuming investigation I believe I now know what happens:
    When building, Unity appears to copy files only if they have changed(!) in source location or if they don't exist in target location. It's irrelevant, whether target file has an older or newer file date or other size. Also files are never removed from target.

    So I had an existing old copy of repo.txt (from a manual copy or restore) in target location. Then any build did not copy repo.txt, as long as I had not committed another version.

    Well, I know, build is probably optimized for a lot of files. But I think it's a bug, that existing files in target are not rewritten solely based on that their source has not changed. It should not be any noticable performance loss to compare date or size, since Unity in any case checks for existence of the file and may read size and change date accordingly (it actually does, which I proved with ProcessMonitor).