Game reports almost only MissingMethodException

I opened a support ticket and was told to ask in Forum or Answers, so I do.

Looking through “Game Performance” of our game I saw that it was basically only reporting one thing, one way or another:

Looking it up it always referred to:

IdleSpecial.Awake ()

Idle Special is a StateMachineBehaviour derived class. The body of Awake looks like this:

SetIdleSpecialTime (1f);
SetEarWiggleTime ();
foreach (var i in idleSpecials)
longestSpecialTime = Mathf.Max (longestSpecialTime, i.averageDuration);

The first two methods are private members of IdleSpecial. Searching the assembly I can confirm that those two are nowhere else called (through SendMessage or something alike)
The foreach is trivial, since it just loops over an array of motions.

So why do I receive MissingMethodException for every possible way Awake was called? (Gameobject gets instantiated, GameObject is in scene and gets activated, Gameobject is in scene active and script gets activated…)

I can’t reproduce it in the editor, where the app runs solid.

If it works in the Editor and the IDE isn’t showing any issues with that code, it very well be a datatype issue in the build. run a check on whats stored in the idleSpecials collection in your build, it might be that the “var” keyword is causing the runtime to assume its some other type, a type that doesn’t have a “.averageduration” field/property.

if you know the type (or interface) of the idleSpecials at compile time, specify that instead of using “var” and see if that fixes your issues. I’d avoid foreach as well for different reasons.

also double check that the datatype of longestSpecialTime is the same as i.averageDuration if one is a float while the other is an int, theres no Max method that takes both ints and floats (only all floats, or all ints). so the exception might be that it can’t find a “public static float Max(float, int)”. Though such an exception should also show up in the editor

To be safe try and cast i.avarageDuration as a float explicitly.

It’s not code stripping gone wrong by any chance?

Hey guys,
thanks for the hints. I found out what it is, although I don’t know how to fix it yet.
It happens on Android only. Motion.averageDuration seems to be getting stripped as @Kiwasi assumed.

This is the logcat message, just to be sure:
MissingMethodException: Cannot find the requested method.
02-23 13:53:05.001 12180 12200 I Unity : at (wrapper managed-to-native) UnityEngine.Motion:get_averageDuration ()
02-23 13:53:05.001 12180 12200 I Unity : at IdleSpecial.Awake () [0x00023] in /Users/alexseeck/Desktop/wk-peekaboo/Assets/Scripts/AnimationControllers/StateMachineBehaviours/IdleSpecial.cs:58

@JoshuaMcKenzie I checked Mathf.Max and parameters and both, a version for floats exists and both parameters are floats.

its interesting how the API documentation doesn’t show Motion having any fields or methods (aside ones inheried from UnityEngine.Object), however sure enough they’re there when checking via intellisense.

it seems like this is the only place where Motion.averageDuration is getting used (in this assembly, unity is likely using it in their assembly). but since you’re using “var” the compiler doesn’t see that its getting used. var implies that the type could be anything at runtime, that its not known at compile time. as said before, try replacing that var:

foreach (UnityEngine.Motion i in idleSpecials)
{
    longestSpecialTime = Mathf.Max (longestSpecialTime, i.averageDuration);
}

doing so should prevent the compiler from stripping it

Quite the opposite actually. var let’s the compiler figure out what the type is for you. It’s still strongly typed.
https://msdn.microsoft.com/en-us/library/bb383973.aspx

1 Like

For now, I just did not use averageDuration on Android. Maybe someone finds this out, or I do this in my private time.

BTW: This was basically the answer from support:

I’ve confirmed that API is definitely present on Android, so the likely scenario is still that this is a stripping issue.

Thank you guys anyway.

I see… I’ve always and only used var on anonymous types, because that’s where I see it’s best used. which lead me to believe that it doesn’t figure out the type at compile.

Also super handy for skipping dumb stuff like this

Dictionary<string, List<GameObject>> lookup = new Dictionary<string, List<GameObject>>();

var lookup = new Dictionary<string, List<GameObject>>();