Tutorials ‐ Using custom scripts - ow-mods/outer-wilds-unity-wiki GitHub Wiki

Getting your mod scripts

  1. Build your mod
  2. Take the .dll file from your mod (in %APPDATA%\OuterWildsModManager\OWML\Mods\[your mod name]) and copy/drag it into your unity project (anywhere will do, as long as it's somewhere in Assets. I like putting mine in Assets/Dlls.)
  3. If your mod dll references other dlls (e.g. if your mod uses code from New Horizons), you also need to copy the other dlls into your unity project.
  4. If it loads without errors, you should be able to add your scripts to GameObjects in editor!

Automatically updating on build

  1. In your .csproj.user file, add this property in the <PropertyGroup> block:
<UnityDllsDir>[path to folder in unity project]</UnityDllsDir>

This defines the folder you want to copy the dll to.

  1. In your .csproj file, add this in the <Project> block:
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="Exists('$(UnityDllsDir)')">
    <Exec Command="xcopy /y &quot;$(TargetPath)&quot; &quot;$(UnityDllsDir)&quot;" />
</Target>

This tells the compiler to copy your dll (TargetPath) into where you specified earlier (UnityDllsDir) after building the dll.

Changing names and namespaces

Unity generates a unique ID for each script based on its name and its namespace, so changing either of those in the original script will unlink it from the Unity version and create missing scripts on any objects it was previously attached to. You can fix this by expanding your imported DLL in the assets window and dragging the correct script into the missing script field on your object, but this will reset any [SerializeField] properties you had on that script.

If your script has a lot of serialized properties and you really don't want to reset all of them, there's a somewhat complicated way to avoid the missing script situation entirely. Prefabs can be opened using Notepad or your code editor of choice, and somewhere inside it you can find the script component that you're trying to rename (you can find it by searching for your serialized properties or by searching for the script's fileID from before it got renamed). In the data for that component is a number labeled fileID, which determines which script from your DLL that component is referencing. When your script gets unlinked, the serialized properties on that component aren't actually reset until you drag a new script in, so if you can find the fileID of your renamed script you can just replace the existing ID inside the prefab. You can usually find the new ID by looking at the script in your imported DLL. Be careful when changing anything in the prefab, because if you do something wrong Unity will crash. Version control (like GitHub) is heavily recommended in case you need to undo something.

When reassigning missing scripts, be careful when dealing with nested prefabs, as a prefab will not allow you to save until all of the missing scripts are fixed. If you make a bunch of changes in a prefab and another prefab inside of it has missing scripts, you'll have to discard all of those changes and fix that other prefab first. Just make sure to fix the nested prefabs before doing anything else and you won't run into that issue.

⚠️ **GitHub.com Fallback** ⚠️