unity-web3-game-kit icon indicating copy to clipboard operation
unity-web3-game-kit copied to clipboard

'Strip engine code' higher than low (player settings) causes important constructors to be stripped from MoralisUser

Open ThePaleOne1 opened this issue 3 years ago • 6 comments

unity version: Unity 2020.3.27f1 building for: WebGL

When you click the connect button that comes as part of the default 'AuthenticationKit' prefab we get an error:

GET http.///52171504 [HTTP/1.1 404 Not Found 39ms] the number after the IP is different every time.
I have no clue what this is doing or why it's erroring, it doesn't crash the game so we can continue.

When the metamask popup comes up and you successfully sign the message, the popup goes away and it all seemingly appears to work perfectly. however, this new error appears in the console:

JsonException: No parameterless constructor defined for 'MoralisUnity.Platform.Object.MoralisUserJsonConvertor'.

line 82 in MoralisUserService.cs, I have tracked down as the cause of the error: user = JsonSerializer.Deserialize<TUser>(cmdResp.Item2.ToString());

STEPS TO REPRODUCE:

  • create a new unity project
  • set build platform to WebGL
  • import Web3 Game Kit Package v1.2.1 into the project. Download link: https://github.com/MoralisWeb3/unity-web3-game-kit/releases/tag/v1.2.1
  • in player settings > WebGL Settings > Other Settings. Strip engine Code should be enabled, and Managed Stripping Level should be medium or high
  • build and run the project with the introduction scene

FOUND THE EXACT ISSUE: When stripping code for the build (an option in player settings) but when a constructor is invoked via reflection is get's stripped too. The easy fix is to turn stripping off or set it to low. The complicated fix: I created a middleman object to deserialize into then set 'user' from there. and in that middleman object's constructor, i put [Preserve] above it so it wouldn't get stripped.

ThePaleOne1 avatar Jun 26 '22 22:06 ThePaleOne1

Thank you for reporting this.

xactant avatar Jun 27 '22 10:06 xactant

I have not been able to reproduce yet. I did take my test project, set stripping to 'High' and ran in desktop build in the IDE. I was able to connect, run battery of tests (web3api, live queries, etc.) and then disconnect with no issue. I ran in 2020.3.34f1

I will try again in a clean project, however are there any other changes you made?

xactant avatar Jun 27 '22 10:06 xactant

Not that I know of. To make sure my steps to reproduce were accurate I tested by making an entirely new project and only did what is already outlined in my steps. I’ll retest it again on my end and see if I missed a step. The only other thing I can think of is the unity version difference. The version I’m using that re-creates the bug is 2020.3.27f1 compared to your 2020.3.34f1. (I need to keep my current old version in order for some other plugins to work)

From: @.> Sent: Monday, 27 June 2022 8:26 PM To: @.> Cc: @.>; @.> Subject: Re: [MoralisWeb3/unity-web3-game-kit] 'Strip engine code' higher than low (player settings) causes important constructors to be stripped from MoralisUser (Issue #110)

I have not been able to reproduce yet. I did take my test project, set stripping to 'High' and ran in desktop build in the IDE. I was able to connect, run battery of tests (web3api, live queries, etc.) and then disconnect with no issue. I ran in 2020.3.34f1

I will try again in a clean project, however are there any other changes you made?

— Reply to this email directly, view it on GitHubhttps://github.com/MoralisWeb3/unity-web3-game-kit/issues/110#issuecomment-1167175079, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALRE4ELRF44XSMZD2FSIVODVRF6VVANCNFSM5Z4U6AAQ. You are receiving this because you authored the thread.Message ID: @.***>

ThePaleOne1 avatar Jun 28 '22 23:06 ThePaleOne1

Is this still an issue - any further information available?

xactant avatar Aug 25 '22 14:08 xactant

Hi, I Have just been working with ‘strip engine code’ set to low in order to avoid the problem altogether. I don’t have any further information, other than the fact that when you set the build setting to medium or high, the MoralisUser constructor get’s stripped from the build because Unity thinks it doesn’t need it. And that, of course, causes many errors when you play the build and try and interact with the MoralisUser code

From: @.> Sent: Friday, 26 August 2022 12:23 AM To: @.> Cc: @.>; @.> Subject: Re: [MoralisWeb3/unity-web3-game-kit] 'Strip engine code' higher than low (player settings) causes important constructors to be stripped from MoralisUser (Issue #110)

Is this still an issue - any further information available?

— Reply to this email directly, view it on GitHubhttps://github.com/MoralisWeb3/unity-web3-game-kit/issues/110#issuecomment-1227331393, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALRE4EI2FDIHTQLO4UWVFYLV256UPANCNFSM5Z4U6AAQ. You are receiving this because you authored the thread.Message ID: @.***>

ThePaleOne1 avatar Aug 26 '22 02:08 ThePaleOne1

Do you have a GameObject in the scene with Moralis code tied to the object? Is it possible AOT in Unity is stripping out the Moralis code from the scene?

xactant avatar Aug 26 '22 12:08 xactant

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 25 '22 12:10 stale[bot]