LogoLogo
Back to raftmodding.com
  • Welcome to the RaftModding docs!
  • ⬇️Getting started
    • Installing Raft Mod Loader
      • Troubleshooting
        • An error occured while fetching for updates
          • Disabling IPV6
          • Changing the DNS
        • The menu inside the game doesn't show up
        • The game crashes on startup
        • There are error notifications in-game
      • Linux or Steam Deck installation
        • Using Bottles
        • Using Wine
      • Configuring your antivirus
        • Windows Defender
        • Malwarebytes
        • Bitdefender
        • Avast
        • Norton
        • AVG
    • Installing a mod
      • Mods in multiplayer
    • How to run multiple raft instances
  • ⚙️MODDING TUTORIALS
    • How to create a mod project
      • The modinfo.json file
    • How to create an AssetBundle
    • How to create console commands
    • Harmony basics
    • Getting access to the modding repositories
  • ⚒️Modding API
    • RAPI
    • Mod
  • 📚Modding Examples
    • Accessing the player instance
    • Adding private variables
    • Spawning dropped items
    • Get selected hotbar item
    • Get the current SteamID
    • Get the current username
    • Giving items to a player
    • Modifying private variables
  • 🌏WEBSITE
    • Mod Slugs (Unique Identifier)
  • 🖥️RAFT DEDICATED SERVER
    • Raft Dedicated Server
Powered by GitBook
On this page

Was this helpful?

  1. MODDING TUTORIALS

How to create an AssetBundle

This tutorial is designed to demonstrate how to import assets into the game, including 3D models, textures, prefabs, particles, and more.

PreviousThe modinfo.json fileNextHow to create console commands

Last updated 1 year ago

Was this helpful?

Let's get started with the requirements! For this tutorial you will need the same requirements as the first tutorial.

1) First, create a new Unity project with the same version as the one required in .

2) Then once the first step is done, download and place it into your Unity Project as shown below. This will allow you to build your asset bundle file.

3) Add your stuff to the asset bundle as shown below.

4) Once you have everything in your assetbundle, build it by right clicking anywhere and clicking on Build AssetBundles as shown below.

5) If your assetbundle has succeeded building you should be able to find it in Assets/AssetBundles; Once you found it, copy it into your mod project folder where your .cs files and your modinfo.json file are located as shown below.

6) Now let's load it into the game using our previous mod made in the How to create a mod project tutorial. Open your mod project and change your start method type from void to IEnumerator and copy the code below into the start method as shown below; You will also need to create a new variable in your mod to be able to access the asset bundle from anywhere in your mod.

IfIEnumerator is underlined in red, simply add using System.Collections;at the top of your mod file.

AssetBundle asset;

public IEnumerator Start()
{
    AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(GetEmbeddedFileBytes("tutorial.assets"));
    yield return request;
    asset = request.assetBundle;
    
}

7) Loading an asset bundle is good, but we also need to unload it when we unload our mod. So, to do that in your OnModUnload method simply add asset.Unload(true); as shown below.

8) Now, to load something from our asset bundle simply use asset.LoadAsset<T>("assetname") for example to load the RedCube that i added into the example asset bundle earlier i can just do asset.LoadAsset<GameObject>("RedCube") as shown below.

If you done everything correctly your asset should now be in the game. For example my red cube spawned in the mainmenu

And here is it! As this can be a bit complicated if you encounter any issue or if you are blocked at a specific step, feel free to join our and ask for help in .

⚙️
😃
Modding Discord
#support
How to create a mod project
this file