FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.39k stars 150 forks source link

Fixed ObjectCaches.Retrieve() cannot find the default constructor when Managed Stripping Level is High #678

Closed ooonush closed 5 months ago

ooonush commented 6 months ago

Added new () constraint for T in ObjectCaches class

677

FirstGearGames commented 6 months ago

Is this problem caused by the fact return new T(); is used instead of Activator?

ooonush commented 6 months ago

Unity code stripping removes unused code. In particular, the AdaptiveLocalTransformTickSmoother class is created only using ObjectCaches.Retrieve(), which uses Activator.CreateInstance() reflection. I suggest replacing reflection with a new() constraint on T. This solved the problem for me.

FirstGearGames commented 5 months ago

I've added a default ctor for the class and put a [Preserve] attribute over it. Originally we went with new() but there were limitations with it, I unfortunately do not recall which.

If adding the new() conditional doesn't throw anything at compile time though, it's safe to say whatever that limitation was it isn't affecting FishNet at the moment. I do not have time to get this into the 4.3.4 release but I will the next.

FirstGearGames commented 5 months ago

Added in manually but cannot merge due to conflicts. Please feel free to make another PR for attribution if you like.