[3.10.2,3.10.3] VRCSceneTemplateInitializer does not create sample scene if UDON preprocessor symbol is defined at first launch since VRCSDK 3.10.2.
anatawa12
VRCSceneTemplateInitializer
does not create the default sample scene when the UDON
preprocessor symbol is already defined on the first launch.Steps to reproduce
- Prepare a VRChat Worlds template with the UDONpreprocessor symbol already defined.
The original report used a project template generated by ALCOM 1.1.5 or earlier. (We added a workaround in 1.1.6.)
However, the issue can also be reproduced by modifying a VCC template to include the
UDON
preprocessor symbol in ProjectSettings.asset
.For reference, ALCOM's Worlds template included the
UDON
preprocessor symbol to reduce the initial Unity launch time by avoiding recompilation of most assemblies.- Launch Unity.
- VRCSceneTemplateInitializershould create the default scene, but it does not.
Cause of the bug
This bug is triggered by the combination of the following conditions:
- UdonSharpDataLocatordoes not exist in the project. This causesAssets/UdonSharp/UtilityScriptsto be generated during the first assembly load.
- The UDONpreprocessor symbol is already defined before the first compilation. This causes[InitializeOnLoad]inVRCSceneTemplateInitializerto run during the first assembly load.
The sequence of events is as follows:
- Unity compiles scripts normally.
- Unity calls the static constructor of VRCSceneTemplateInitializerbecause of[InitializeOnLoad].
VRCSceneTemplateInitializer
checks SessionState.GetBool(HasRunStateKey, false)
, which is false
, so it sets HasRunStateKey
to true
and registers an EditorApplication.delayCall
to generate VRCDefaultWorldScene
.- Unity calls some [InitializeOnLoad]methods from UdonSharp, and UdonSharp generatesAssets/UdonSharp/UtilityScripts.
- Unity recompiles Assembly-CSharpand reloads the domain.
Note that the registered
delayCall
is never executed before this reload.- Unity calls the static constructor of VRCSceneTemplateInitializeragain because of[InitializeOnLoad].
This time,
SessionState.GetBool(HasRunStateKey, false)
returns true
, so nothing happens.As a result, the logic that generates
VRCDefaultWorldScene
is never executed.(The order of steps 2 and 3 may differ, but the result is the same.)
For comparison, the following sequence does
not
cause the bug when the UDON
symbol is not initially defined:- Unity compiles scripts normally, but the VRC.SDK3.Editorassembly containingVRCSceneTemplateInitializeris not compiled because of"defineConstraints": ["UDON"].
- Unity calls some [InitializeOnLoad]methods from UdonSharp, and UdonSharp generatesAssets/UdonSharp/UtilityScripts.
- EnvConfig.cschecks forVRC.Udon.UdonBehaviourand adds theUDONpreprocessor symbol.
- Unity recompiles all assemblies and reloads the domain.
- Unity calls the static constructor of VRCSceneTemplateInitializerbecause of[InitializeOnLoad].
SessionState.GetBool(HasRunStateKey, false)
returns false
, so it sets HasRunStateKey
to true
and registers an EditorApplication.delayCall
that generates VRCDefaultWorldScene
.- Unity executes the EditorApplication.delayCall, andVRCDefaultWorldSceneis generated correctly.
Suggested fix
The issue is that
HasRunStateKey
is set to true
before the EditorApplication.delayCall
is actually executed.I believe moving the
HasRunStateKey
assignment into the EditorApplication.delayCall
lambda would fix the issue.Log In
anatawa12
As mentioned above, although the original report used an ALCOM-generated template, this issue is reproducible with custom VCC templates, so the issue itself is not specific to ALCOM.
Also, I have already implemented a workaround/fix on the ALCOM side for the next release.
venn02_ヴェン
anatawa12
If that's the case, I think all we need to do is output the VCC logs, and ALCOM can handle the fix from their end.
We mustn't forget that ALCOM is, after all, an unofficial tool.
Val_eins
Why aren't you using VCC?
天白ゆうか
VCC is performing tasks that are not normally done, so why are you asking them to officially fix it? If you are an Alcom engineer, shouldn't you be able to fix Alcom yourself to prevent this bug from occurring?
If you can't do that, then I think Alcom should be taken private immediately, before more people have their important projects ruined because of bugs like this.
venn02_ヴェン
If the issue can only be reproduced by performing an operation in VCC that you wouldn't normally do, isn't that a bug specific to ALCOM?