CoreAPI
CoreAPI provides access to core game components such as Hub, VWorld, VRoomManager, and PersistentData.
Methods
GetHub()
Gets the main Hub object of the game.
public static Hub GetHub()
Returns:
Hub- The main game hub object
Example:
var hub = CoreAPI.GetHub();
if (hub != null)
{
MelonLogger.Msg("Hub retrieved successfully!");
}
GetVWorld()
Gets the VWorld object from Hub.
public static VWorld? GetVWorld()
Returns:
VWorld?- Virtual world object ornullif not found
Example:
var vworld = CoreAPI.GetVWorld();
if (vworld != null)
{
MelonLogger.Msg("VWorld initialized");
}
GetVRoomManager()
Gets the room manager from VWorld.
public static VRoomManager? GetVRoomManager()
Returns:
VRoomManager?- Room manager ornullif not found
Example:
var roomManager = CoreAPI.GetVRoomManager();
if (roomManager != null)
{
MelonLogger.Msg("VRoomManager available");
}
Usage:
var roomManager = CoreAPI.GetVRoomManager();
if (roomManager != null)
{
// Can be used to get room information
var rooms = RoomAPI.GetAllRooms();
}
GetPersistentData()
Gets the game's persistent data (saved player data).
public static Hub.PersistentData? GetPersistentData()
Returns:
Hub.PersistentData?- Persistent data ornullif not found
Example:
var pdata = CoreAPI.GetPersistentData();
if (pdata != null)
{
MelonLogger.Msg("Persistent data loaded");
}
Practical Examples
Checking Game Initialization
bool IsGameInitialized()
{
return CoreAPI.GetHub() != null &&
CoreAPI.GetVWorld() != null &&
CoreAPI.GetVRoomManager() != null;
}
public override void OnUpdate()
{
if (IsGameInitialized())
{
// Game is fully initialized
// Can use other APIs now
}
}
Getting Base Components on Mod Startup
public override void OnInitializeMelon()
{
MelonCoroutines.Start(WaitForGameInit());
}
IEnumerator WaitForGameInit()
{
while (!IsGameInitialized())
{
yield return new WaitForSeconds(1f);
}
MelonLogger.Msg("Game initialized!");
var hub = CoreAPI.GetHub();
var vworld = CoreAPI.GetVWorld();
var roomManager = CoreAPI.GetVRoomManager();
// Now safe to use APIs
InitializeMod();
}
Notes
Important
All CoreAPI methods may return null if the game is not fully loaded yet. Always check for null before using the returned objects.
Tip
Use CoreAPI to check game readiness before using other API modules (PlayerAPI, RoomAPI, etc.).
Dependencies
CoreAPI uses:
- ReflectionHelper for accessing private fields of game classes
- Classes from the
Mimicnamespace
See Also
- ReflectionHelper - Reflection helper methods
- RoomAPI - Room management
- ManagerAPI - Access to other managers