Skip to content

Adding GameObjects using Asset Classes

PrimeSonic edited this page Sep 1, 2020 · 4 revisions

As of version 2.0.4, a new set of classes was added to the SMLHelper.V2.Assets namespace.
These classes were created to greatly simplify the process of adding GameObjects into the game for common use cases.
Depending on the complexity of your GameObject, you may need to include your own custom prefab handling.

There are a few classes you will want to know about

  • Spawnable :ModPrefab
    • Used for any item that can be spawned in the game and could be added to the player's inventory.
    • Requires you to handle your own spawning but has optional ability to add to the random spawn table.
    • PdaItem :Spawable
      • Used to add PDA/Scanner data to a Spawnable object.
      • Can be used to make Custom Scanner Fragments.
      • Buildable :PdaItem
        • Used for items created using the Habitat Builder
        • CustomFabricator :Buildable
          • Used for easily adding new fabricators into the game with new crafting trees
      • Craftable :PdaItem
        • Used for items created using a fabricator
        • Equipable :Craftable
          • Used for upgrade modules that go into Equipment slots

All these are abstract classes which all inherit from the ModPrefab class. What is special about them is that they offer additional abstract and virtual properties that will help guide you through all the requirements needed to get your item into the game without missing anything important. Each one adding and building upon what it inherits from to make adding your custom GameObject as simple as we can.

All you do is inherit one of these classes and override as needed.
The class you create will represent the modded prefab for the GameObject in the game.

using SMLHelper.V2.Assets;

internal class MyItem : Craftable
{
    // Override all abstract members
    // Optionally override any virtual members
}

The Visual Studio/Intellisense documentation will guide you through what each of these abstract and virtual are for.

Once you are ready, just call the Patch() method on an instance of your class to get the ball rolling.
These classes were design to handle all the core patching needed to get a modded GameObject up and running.

[QModCore]
public static class MyMainClass
{
    [QModPatch]
    public static void MyModPatch()
    {
        var myItem = new MyItem(); // Create an instance of your class
        myItem.Patch(); // Call the Patch method
    }
}

Remember: These classes only handle basic functionality. Any other custom behavior or interaction will require that you include the necessary patches or custom code to make sure your item behaves as intended.