I'm updating a mod for Planetbase but the entry method gives me issues. The error is:
No overload for 'Update' matches delegate 'Action<UnityModManager.ModEntry,float>'
Here is the snipped of the source code that I have problem with, error at line 13:
using Planetbase;
using UnityEngine;
using System;
using UnityModManagerNet;
namespace Tahvohck_Mods
{
public class BetterHours_Main
{
[LoaderOptimization(LoaderOptimization.NotSpecified)]
public static void Init(UnityModManager.ModEntry modData)
{
modData.OnUpdate = Update;
}
#pragma warning disable IDE0060 // Remove unused parameter
public void Update(UnityModManager.ModEntry modData, PlanetDefinition planetDefinition)
#pragma warning restore IDE0060 // Remove unused parameter
{
StatsCollector sCollector = Singleton<StatsCollector>.getInstance();
EnvironmentManager eManager = Singleton<EnvironmentManager>.getInstance();
_ = (Singleton<EnvironmentManager>.getInstance().getDayTime() Singleton<EnvironmentManager>.getInstance().getNightTime()) / 6f;
if (sCollector != null && eManager != null)
{
float dayHours = (float)GetDayHours(planetDefinition);
_ = (float)((eManager.getDayTime() (double)eManager.getNightTime()) / (dayHours / 6.0));
}
}
Help would be welcome as I just started working with Planetbase mods.
CodePudding user response:
The problem is in this statement:
modData.OnUpdate = Update;
The reason is that your Update method doesn't match the type that is expected by the OnUpdate event. If you look at the error message, it will tell you what is wrong:
No overload for 'Update' matches delegate 'Action<UnityModManager.ModEntry,float>'
The bolded part tells you the type that is required for the OnUpdate event. Action is a generic delegate type, and the types in the angle brackets tell you the required parameter types.
You can see here that it is expecting a method that receives a ModEntry as the first parameter and a float as the second parameter. Your Update method takes PlanetDefinition as the second parameter, so it doesn't match.
