Skip to content

Using Custom Objects

Leaxx edited this page Nov 26, 2023 · 4 revisions

Introduction

Are you tired of the same old items in the game? Adding custom objects to your mod can breathe new life into the gameplay. Let's explore how you can make this happen.

Prerequisites: Load Your Assets

Before diving into creating custom objects, make sure you've loaded your custom assets. If you haven't done this yet, follow this guide.

Making It Work

Once you've instantiated your object in the CustomObjectsRegistration method, you're ready for the next step.

Basic custom object setup

If you want a standard object that can be picked up, placed, and so on, you need to do it like this.

        public override void CustomObjectsRegistration()
        {
            base.CustomObjectsRegistration();

            GameObject obj = Instantiate(LoadAsset<GameObject>("example", "example", "", ".prefab"));

            ModHelper.Instance.AddBasicObjectLogic(obj, objName, objDescription, price, weight, canFindInCrates, canBuyInStore);

            CustomObjectsManager.Instance.RegisterObject(obj, "ObjectID");
        }
  • canFindInCrates & canBuyInStore are currently not available but should still be set.

You can adjust the object's position using these:

            ModHelper.Instance.AdjustCustomObjectPosition(obj, throwRotation, position);
            ModHelper.Instance.AdjustCustomObjectTrunkPosition(obj, position, rotation, dimensions);
  • All of the arguments, except obj, are Vector3s.

For AdjustCustomObjectPosition:

  • throwRotation specifies the euler angles that the object will have, relative to the player once the item is no longer being held (dropped)
  • position specifies the object's position relative to the player while being held

For AdjustCustomObjectTrunkPosition:

  • position & rotation specifiy the adjustments you may need to make so that the object doesn't clip through the body panels/roof rack
  • dimensions specifies the dimensions of the object, refer to this guide for more information.

Using them in-game

If you made the object findable in crates or buyable in stores, once this feature works, it should appear there.

For manual spawning, use:

CustomObjectsManager.Instance.SpawnObject("ObjectID", position, rotation);
  • rotation is a Vector3, as it modifies the euler angles. There is also a SpawnObject(ID, position) variant.

Next steps

If you'd like to create custom engine parts, follow along.

Clone this wiki locally