Using custom assets - theLeaxx/JaLoader GitHub Wiki

Introduction

Custom assets refer to any additional resources, such as textures, models, sounds, or other files, that your mod utilizes. If your mod makes use of custom assets and relies on the "LoadAsset" function, you need to set a specific flag to indicate this. This guide will walk you through the process of enabling the use of custom assets in your mod.

If you don't know how to create assets, go here.

Enabling Custom Assets

In your mod's code, you can enable the use of custom assets by setting a boolean property. If your mod uses the "LoadAsset" function, you need to set this property to true.

public override bool UseAssets => true;

How to actually load the asset

Once you've enabled custom assets in your mod, you can utilize the "LoadAsset" function to load and use custom resources dynamically during runtime. This function allows your mod to access and integrate custom assets seamlessly.

You can use this function anywhere, anytime in your code. For example:

var loadedObject = LoadAsset<T>("assetName", "prefabName", "fileSuffix", "prefabSuffix");
  • T is the type that will be returned; this can be, for example, GameObject, or Texture2D, and so on
  • assetName is the exported assetbundle's name
  • prefabName is the prefab's name in the editor
  • fileSuffix is the exported assetbundle's file suffix, usually this is just blank (""), although usually .unity3d is used
  • prefabSuffix is the prefab's suffix; for GameObjects, use .prefab; for other types, use their respective suffix, as in the editor

You can then use the loadedObject variable anywhere in your code - for example, if it's a GameObject, you can now do Instantiate(loadedObject);