#[Modding] How to modify all current and future entities of targeted ObjectID

1 messages · Page 1 of 1 (latest)

zenith sundial
#

Core Keeper Modding SDK exposes a "built in" mechanism to inform mods about a spawning object.

When a save of Core Keeper is loaded, all objects are considered spawning, this means you can effectively modify data of all objects in the world, current and future.

API.Server.OnObjectCreated on the Server, which works on Dedicated Servers; Single player games and for Host on multiplayer game. This is the event you should use to react and modify the data of entities that load into the game or will be spawned, for example if you want to change the HealthCD of every PlayerGrave this is the one you want.

API.Client.OnObjectSpawnedOnClient is the Client equivalent, mind that only visual data changes make sense to use it, other data like changing health will not work.

As of v1.1.2.10
API.Server.OnObjectCreated is an event with a signature of void OnObjectCreated(Entity entity, EntityManager entityManager)


Be very careful with amount of work you do inside this callback, it's called by the system on every entity that is considered an Object (has IsObjectCD) once.

All entities which trigger this event should have ObjectDataCD but it's not guarded by the event system.


Example usage

public class Playground : IMod
{
    public void EarlyInit()
    {
        API.Server.OnObjectCreated += OnObjectCreated;
    }

    public void Init()
    {
    }

    public void ModObjectLoaded(UnityEngine.Object obj)
    {
    }

    public void Shutdown()
    {
        API.Server.OnObjectCreated -= OnObjectCreated;
    }

    public void Update()
    {
    }

    bool IMod.CanBeUnloaded() => true;

    private void OnObjectCreated(Entity entity, EntityManager manager)
    {
        var objectCD = manager.GetComponentData<ObjectDataCD>(entity);
        if(objectCD.objectID == ObjectID.PlayerGrave)
        {
            // It's a grave!
        }
        else
        {
            // It's some other object with ObjectDataCD
        }
    }
}
#

[Modding] How to modify all current and future entities of targeted ObjectID

quiet stirrup
#

Alright, this is pretty much what we need! Thanks for the explanation. I'll just have the function check if the objectCD.objectID is contained within a set list of ObjectID's and if it is to add a FactionCD component and set it to have befriended FactionID.Explosion so it shouldn't be too much work (especially compared to my previous idea of querying every entity each time we spawn a bomb and doing the same for each entity).