Skip to content

ModAssets class ​

Namespace Lustral · Assembly Lustral.Api

Loads Unity asset bundles shipped with a mod, on both Mono and IL2CPP:

csharp
var bundle = Assets.LoadBundle("Assets/ui.bundle");
var panel = bundle.Load<GameObject>("Panel");

This also works in IL2CPP games whose builds do not include Unity's AssetBundle class, because Lustral calls the engine directly. Bundles must be loaded on the main thread, from Mod.OnGameReady onward.

csharp
public sealed class ModAssets

Remarks ​

Build bundles with the game's Unity version or a close version; Unity cannot load bundles built with a newer version. Ship bundles in the mod's folder (<None Include="Assets\**" CopyToOutputDirectory="PreserveNewest" /> in the project file), or embed them in the mod's assembly and load them from bytes.

Methods ​

LoadBundle(string) ​

csharp
public ModAssetBundle LoadBundle(string path);

Loads an asset bundle file. Relative paths are resolved against the mod's folder (ModInfo.Directory). Loading a file that is already loaded returns the same bundle, because Unity loads each bundle only once.

Exceptions

  • FileNotFoundException: The file does not exist.
  • InvalidOperationException: Unity could not load the bundle (the game's log, Player.log, contains the reason), or the method was called before the game was ready or outside the main thread.

LoadBundle(byte[]) ​

csharp
public ModAssetBundle LoadBundle(byte[] data);

Loads an asset bundle from memory, such as a bundle embedded in the mod's assembly: Assets.LoadBundle(ReadResource("MyMod.ui.bundle")).

Exceptions

  • InvalidOperationException: Unity could not load the bundle (the game's log, Player.log, contains the reason), or the method was called before the game was ready or outside the main thread.

Mods are third-party software. Lustral does not verify their behavior and is not responsible for any damage they cause.