Keep Getting TargetParameterCountException When Updating to U2021.2

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
grofit
Posts: 13
Joined: Sun Feb 07, 2016 2:47 pm

Keep Getting TargetParameterCountException When Updating to U2021.2

Post by grofit »

I have just had to pick back up an old project which I was using U2018 for and it was working fine in there but I have updated to U2021 and re-installed the Dialogue Manager and a few other bits, everything compiles and runs fine but every time I try to interact (via proxy selector and use) it blows up with TargetParameterCountExceptions.

Code: Select all

TargetParameterCountException: Number of parameters specified does not match the expected number.
System.Reflection.RuntimeMethodInfo.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) (at <47ab72e0328040438980f9c23608e1ec>:0)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <47ab72e0328040438980f9c23608e1ec>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <47ab72e0328040438980f9c23608e1ec>:0)
Language.Lua.LuaMethodFunction.InvokeMethod (Language.Lua.LuaValue[] args) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Interpreter/LuaValue/LuaMethodFunction.cs:35)

Code: Select all

Dialogue System: Lua code 'return IsTimeAfter("18:02") == true' threw exception 'Number of parameters specified does not match the expected number.'
UnityEngine.Debug:LogError (object)
PixelCrushers.DialogueSystem.Lua:RunRaw (string,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:228)
There are a few others similar to this, and while my first thought was "oh thats my method and its wrong" it basically does:

Code: Select all

// in an MB somewhere
Lua.RegisterFunction("IsTimeAfter", this, SymbolExtensions.GetMethodInfo(() => this.IsTimeAfter(String.Empty)));

// In another file somewhere
public static bool IsTimeAfter(this IHasGameState hasState, string time)
{
	var proposedTime = time.GetProposedTime();
	var effectiveTime = hasState.GameState.GetEffectiveTime();
	return effectiveTime > proposedTime;
}
The odd thing is I can see when I enter the scene it runs this code, and it works fine, no errors, however I speak to anyone and it blows up.

Hopefully I am being an idiot or there is some simple fix but struggling to debug whats going on as its all down to reflection calls.
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Keep Getting TargetParameterCountException When Updating to U2021.2

Post by Tony Li »

Hi,

Are you sure that method was running correctly as a Lua function in Unity 2018? With the default Lua implementation (LuaInterpreter), I don't think Lua.RegisterFunction() can work with extension methods because Lua will get confused with the 2-parameter method signature. Can you rework your method so it's not an extension method with 'this'?
grofit
Posts: 13
Joined: Sun Feb 07, 2016 2:47 pm

Re: Keep Getting TargetParameterCountException When Updating to U2021.2

Post by grofit »

Yeah I can do, but i'm almost certain it was working, and when the scene first loaded it ran that extension method fine as I was debugging.

Anyway if thats the issue I will map it all over, thanks for getting back to me so quick!

-- Edit

Just thought now, that it probably ran when the scene loaded as it was evaluating all the registration functions so it wasn't doing a lua invocation, just trying to get a handle on the method I imagine.
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Keep Getting TargetParameterCountException When Updating to U2021.2

Post by Tony Li »

Invoking the function before it's registered could certainly be another issue, but you will also need to straighten out the method signature.
Post Reply