Il2cpp with UFPS 1 - can't get it to work

Hi,
we’re making a multiplayer game with the first version of UFPS and everything was working fine, but we’ve decided to switch from Mono to Il2cpp and problems have shown up.

From this thread: https://legacy.opsive.com/assets/UFPS/forum/index.php?p=/discussion/1685/how-to-fix-executionengineexception-attempting-to-jit-compile-error-on-non-desktop-platforms it seems the problem are those Empty methods in the vp_Value class. The class looks like this:

public class vp_Value<V> : vp_Event
{
#if !ENABLE_IL2CPP
    public static T Empty<T>() { return default(T); }
    public static void Empty<T>(T value) { }
#endif

    public delegate T Getter<T>();
    public delegate void Setter<T>(T o);

    public Getter<V> Get;
    public Setter<V> Set;

        ... //rest of the code
}

Whenever I want to access some value in build via Get or Set defined in vp_PlayerHandler I get the NullReferenceException: Object Reference not set to an instance of an object. But only on Remote Players and AI.

Example:
I instantiate my prefab of AI player and during the Awake call the InitMaxSpeeds method in the vp_BodyAnimator class is called:

protected virtual void InitMaxSpeeds()
    {
        Debug.Log("Player.IsLocal " + Player.IsLocal);
        Debug.Log("GET: " + Player.IsLocal.Get());

        if(Player.IsLocal.Get())
        {
             ...//rest of the code
        }
}

where IsLocal is defined as: public vp_Value IsLocal.

The line with the if statement has always thrown NullRefException. So I put those two debugs in there. The output is:

Player.IsLocal vp_Value`1[System.Boolean] NullReferenceException: Object reference not set to an instance of an object.
It’s not just this case where it is happening but since it’s always the variable of vp_Value I guess it’s the same problem in all cases.

I’ve tried to go along this: https://docs.unity3d.com/Manual/ScriptingRestrictions.html to somehow make the Empty methods available in Il2cpp (and not use the #if !ENABLE_IL2CPP directive in vp_Value class), but I have absolutely no idea how to use it and this error shows up:
ExecutionEngineException: Attempting to call method ‘vp_Value`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]::Empty<System.Boolean>’ for which no ahead of time (AOT) code was generated.

Also, the thread I’ve mentioned earlier says to create placeholder methods for events that have no callback when the Empty methods are not in use, but I’m stuck and clueless of how to do it in my case for vp_Value class and its Get and Set method.
So I would really appreciate some help in this matter.

The official forum for this asset is in read-only mode and the newer version, as far as I am aware, is made by a different group, so that’s why I’m putting it here.

Thanks!

Hi,

I used UFPS with Control Freak2 in a project.

I created the map, and the main character with UFPS, and added CF2 for mobile controls, i build the game for android with IL2CPP scripting backend and game works.

Then i added a canvas to my project for game end menu. After this point, everything works perfect while building with Mono Scripting Backend, but controls are not working when i build with IL2CPP Scripting Backend. Stucked here for a month and can’ t find a solution for this issue. CF2 mobile control buttons can be pressed and animate, but codes at background are not working, i mean character does not walk or run or shoot or jump etc.

I’ve tried several ways such as changing canvas sort layer and gameobjects under canvas Pos Z to back to mobile control’s canvas etc…

Now even i delete the canvas i’ ve added for game end menu, game does not work anyway.

Pfff.

Adding the following to the constructor of vp_Value<> fixes the issue:

#if (!UNITY_IPHONE)
Empty<V>();

Empty(default(V));
#endif

Empty is not AOT compiled as it’s not referenced by the code (and the body of those functions are empty), adding this to code the compiler needs to process will result in the code being generated during the build.

1 Like

Thank you for this! Trying it out now in our project.