General modding

From Edge Of Eternity - Eternal Forge Modkit Wiki
Revision as of 22:41, 20 December 2018 by Virror (talk | contribs) (Scripting basics)
Jump to: navigation, search

Scripting basics

Basics

Before you start your Journey on making script mods for Edge of Eternity, you have to understand the limitations that come with the mod kit framework you are working with. First of all, you should always start from a template project, which is automatically setup for modding and provide simple examples. These template projects are available from GitHub, the link is in the Official EOE Modding Guide.

Second, only one script can inherit from the IModInterface abstract class. This is because this script acts as an entrance point to all scripting logic in your mod, similar to how the Program class is usually the entrance point in C# projects. The IModInterface has several overridable methods, such as the "OnIngameUpdate" method (similar to Update), which allows you to hook logic to in game events. You can, however, have as many classes in your project as you like. And your entrance point IModInterface script can reference any of these classes.

Another limitation, one that I had trouble with initially, is that scripts attached to GameObjects in Additive scenes will NOT BE CALLED. This limitation is due to the way your mod assembly gets loaded into the game at runtime. But you can always attach a MonoBehaviour derived script to a GameObject. You can also create a Prefab, and load it Dynamically into the game.

I haven't tried attaching a MonoBehaviour to a prefab, and then loading it Dynamically through script. This may be another limitation.

A temporary limitation, one that the developers hope to fix in the future, is that you can't use DLLs (Dynamically Linked Library) from the Asset Store or from other projects in your mod. All of the code in your mod must be C# Files. Be wary of this when you import Assets from the Unity Asset Store.

And lastly, you cannot create additional resources inside the "Resources" folder. This is because of the way Unity builds packages into asset bundles. It'll only understand Resources that were created from the actual game project, but not through mods that are dynamically loaded into a game. So don't try using "Resources.Load" on resources you created in your mod project. Only use this method on resources from the actual Edge of Eternity game project.

Editor Scripts

Just like any Unity Game, you cannot build Editor Scripts. Usually developers will put the Editor scripts in special "Editor" folders. When it's time to build a game, the compiler will ignore any scripts inside of these special folders.

The current EOE modding tools do not automatically do this for the user. So if you include any editor scripts from any assets you download from the Unity Asset Store (you'll see Editor folders in the import preview), you need to manually tell the compiler to not build these scripts.

To do this, all you need to do is open up every Editor script in a text editor, and wrap the whole script in a UnityEditor preprocessor.

//Insert this at the top of the script, above any namespaces
#if UnityEditor
//A simple Editor Script
class SampleEditorClass : UnityEditor.Editor {
   //Editor Code
}
//Don't forget to add endif at the end
#endif

Adding References

This is a simple fix if you are have issues with default Unity References not being included in your project, such as the TextMeshPro references (TMPro). You most likely will run into these issues if you opened up a template sample project from Kaldorei's EOE modkit github page. If this is the case, you should have a ModScripts.asmdef file at the root of your assets folder. All you need to do is click on it, look at the details in the inspector, and look for References near the top.

Press on the add button, you'll see a new item appear, a missing reference. The right section of this reference is a small circle. Select it, and find the appropriate reference you need (make sure to select the editor references too). For TextMeshPro, you'll need to select two references, "Unity.TextMeshPro" and "Unity.TextMeshPro.Editor". At the bottom of the inspector, press the apply button. The references should now be included in your project, so you shouldn't have issues referencing them now in your scripts.

Making an additive scene