Is it possible to get Unity to compile specific scripts even if it can't compile the entire project because of errors.
I've been doing a lot of experimentation with different ways to create a custom event system and the one I am currently on is definitely the most promising if I can just get this last bit to work.
I have a custom editor script that allows you to create and manage events. Adding an event here creates a scriptable object that just holds the name of the event.
I'm using scriptable objects here so that theoretically two people could be working at the same time on different machines and create totally different events. They could then merge what they were working on and receive no problems from the event manager here because it parses through the scriptable objects and generates the initial list based on those when the custom editor window is opened. Whereas otherwise, they would be editing the same file and causing merge conflicts.
When that editor window saves from an auto-save or the save button, all the scriptable objects are parsed and a C# file is generated/updated that is just filled with those event names as constant event IDs.
public static class EventIDList
{
public const string Aim = "Aim";
public const string AimLook = "AimLook";
public const string AimLookVertical = "AimLookVertical";
public const string Attack = "Attack";
public const string Jump = "Jump";
public const string Movement = "Movement";
public const string Sprint = "Sprint";
public const string Zoom = "Zoom";
}
This file is ignored in the version control for the reason I talked about above about preventing merge conflicts. This file is meant to be generated by the event manager from those scriptable objects. However, if after pulling from another machine I realized that the script I had wrote to actually create this file was not being executed.
[InitializeOnLoad]
public static class InitializeEventList
{
static InitializeEventList()
{
CreateFile();
}
public void CreateFile() { ... }
}
Apparently if a Unity project has compiler errors before it is launched it won't run these InitializeOnLoad scripts. The compiler errors are because many scripts are referencing the EventIDList script but that file hasn't been generated yet because of the compiler errors (bit of a cyclic problem).
So in theory, if I could get unity to compile specific files even if it can't compile the entire project, I could get it to compile the necessary scripts to generate the file. Then after the file is generated all other compiler errors would go away.
Answer by Lvl1Lasagna · Jun 12, 2021 at 05:12 AM
I posted this on reddit as well and it was solved over there by u/SilentSin26 using Assembly Definition Files. https://www.reddit.com/r/Unity3D/comments/nxxqa0/is_it_possible_to_have_unity_compile_some_files/h1hfg0y/?context=3
Your answer
Follow this Question
Related Questions
Do Unity Editor GUI Utilities (Handles.DrawLine & EditorGUI.DrawRect) have limitations? 2 Answers
EditorWindow and serialization of scene objects 0 Answers
How can I display a scriptable object in a custom editor ? 1 Answer
How to make my scene object reference survive the button play 1 Answer
Editor Int sliders affecting each other 0 Answers