Skip to content

Internal Development Philosophy

Brandon Smith edited this page Apr 30, 2022 · 6 revisions

When developing with modding at mind, it will be important to re-think about how we approach normal problems.

Typically the notion would be creating monobehaviours at the game level and hoping that the modders can access it... well, we can.. but we shouldn't do that. Instead we can put "placeholder" or "data components" onto the game object. This allows us to share accurate monobehaviours, without giving our source code to the modder and additionally giving them the full capabilities of the game.

The layout looks like this: The Mod SDK will be referenced in both projects, the modder's project and the game that you are making.

image

InternalMonoBehaviour

If we want to interact with our "data components" we have to create an InternalMonoBehaviour. This will automatically generate the reflection code to link up with another component, this happens on scene load from the ModManager component that gets added into a global scene when the game launches.

If you want to access the the "data component" the public variable m_exposed will suffice.

Note: All data must be serializable, if you want it to be transferred between the mod to the game.

Example: Public Monobehaviour given to the modder

public class AddressableObjectSpawner : MonoBehaviour
{
        public bool destructAfterCreation = true;
        public AssetReferenceGameObject ObjectAddress;
}

Internal Monobehaviour that gets attached at runtime

[RequireComponent(typeof(AddressableObjectSpawner))]
public class InternalAddresableObjectSpawner : InternalMonoBehaviour<AddressableObjectSpawner>
{
    public override void Init()
    {
        if (m_exposed.ObjectAddress != null)
        {
            //Spawn();
            return;
        }

        // If the object address is not loaded yet, lets start loading it.
        //m_exposed.ObjectAddress.LoadAssetAsync<GameObject>().Completed += InternalAddresableObjectSpawner_Completed;
    }
}

Syncing Editor Data

image

Asset Labels

You will have to edit the SDK and go to the ModUserSettings.cs file found in the ModSDK target and add/remove/modify any enum flag in ModAssetLabels.

Physics Layers

You will have to edit the SDK and go to the ModUserSettings.cs file found in the ModSDK target and add/remove/modify any enum flag in ModPhysicsLayers.

This will automatically update the user's physics layers when they open the modtool sdk editor for the first time. Additionally, keep in mind that the maximum physics layers there can be at anytime is 32, while the first 5 are reserved to Unity.

Tags

You will have to edit the SDK and go to the ModUserSettings.cs file found in the ModSDK target and add/remove/modify any enum flag in ModObjectTags.

Clone this wiki locally