Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Changing a constant in one class doesn't recompile other classes that reference it #81

Open
omgitsraven opened this issue Apr 24, 2021 · 1 comment
Labels
blocked Blocked due to being dependent on a larger unimplemented system bug Something isn't working
Milestone

Comments

@omgitsraven
Copy link

Describe the bug in detail:
If you make one class reference a constant in another class, and then only change the other class, the first class will have a stale value until you force it to recompile.

Provide steps/code to reproduce the bug:

  1. Make the following U# script and put it on a UdonBehaviour in the scene:
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class ConstHaver : UdonSharpBehaviour{
	public const int myVal = 3;
}
  1. Make the following U# script and put it on a UdonBehaviour in the scene:
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class ConstPrinter : UdonSharpBehaviour{
	
	public const int doubleVal = ConstHaver.myVal * 2;
	
	void Start(){
		Debug.Log(doubleVal);
	}
	
}
  1. Enter play mode, and note that the console says 6. Exit play mode.

  2. Edit ConstHaver and change its myVal value to 5.

  3. Enter play mode, and note that the console still says 6. Exit play mode.

  4. Edit ConstPrinter and add Debug.Log("hi"); on a new line after the existing Debug.Log

  5. Enter play mode, and note that the console now says 10 (and then hi).

Expected behavior:
I expected that either the constants would either be set at runtime, or changing one would cause all of the scripts that reference it to be recompiled (or that the readme would warn about this behaviour).

@omgitsraven omgitsraven added the bug Something isn't working label Apr 24, 2021
@MerlinVR
Copy link
Owner

This a specific interaction between constant variables and field initializers. All scripts do get recompiled, but U# field initializers use the assemblies compiled by Unity to evaluate constants and such. So what happens is you change your script -> U# compile gets triggered using old Unity assemblies with the old constant value -> unity compile runs and reloads assemblies. Of note is that this will not be an issue when you upload the world, since world upload requires that you have the assemblies compiled and forces a compile for the world upload.

This may be addressed in the future if the underlying handling for field initializers changes significantly.

@MerlinVR MerlinVR added the blocked Blocked due to being dependent on a larger unimplemented system label Apr 24, 2021
@MerlinVR MerlinVR added this to the UdonSharp 1.0 milestone Sep 10, 2021
MerlinVR added a commit to ureishi/UdonSharp that referenced this issue Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked Blocked due to being dependent on a larger unimplemented system bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants