push-pop / Unity-MVVM

Lightweight MVVM Framework for Unity3D
MIT License
323 stars 27 forks source link

Sample scenes not working in 1.1.4 #78

Closed GordeyChernyy closed 3 years ago

GordeyChernyy commented 3 years ago

I've got these errors in sample scenes:

NullReferenceException: Object reference not set to an instance of an object
UnityMVVM.Binding.DataBindingBase.FindViewModel () (at Library/PackageCache/com.push-pop.unitymvvm@6ea25b4f7d/Scripts/Binding/DataBindingBase.cs:78)
UnityMVVM.Binding.DataBindingBase.Awake () (at Library/PackageCache/com.push-pop.unitymvvm@6ea25b4f7d/Scripts/Binding/DataBindingBase.cs:100)
GordeyChernyy commented 3 years ago

After entering play mode a second time I have the same errors and need to restart Unity to make it work again but only one time

push-pop commented 3 years ago

@GordeyChernyy what sample scene are you seeing this on?

push-pop commented 3 years ago

And how are you loading the samples? Through Unity Package Manager? OpenUPM?

GordeyChernyy commented 3 years ago

I used Unity Package Manager and used MVVMTest sample through package download sample feature

push-pop commented 3 years ago

Cool. Will try to re-pro. FYI I'm suggesting people use OpenUPM now since it supports versioning: https://openupm.com/packages/com.push-pop.unitymvvm/

GordeyChernyy commented 3 years ago

I never tried to install the package using OpenUPM will try now. Thanks!

push-pop commented 3 years ago

Personally am using Scoped Registry with Unity Package Manager: https://docs.unity3d.com/Manual/upm-scoped.html

The OpenUPM dev recommends using his commandline tool.

I will try to add instructions soon to the repo

GordeyChernyy commented 3 years ago

I installed the package through OpenUPM but it has the same issue. It is running fine for the first time but then starts throwing exceptions on the second time you enter play mode

GordeyChernyy commented 3 years ago

It might be Unity 2020 just checked in 2019 it works but let me check empty project in 2020

GordeyChernyy commented 3 years ago

The package works in empty project 2020 but can't get it working in my project, I removed the Library folder but it didn't help

push-pop commented 3 years ago

hmm just the samples don't work or your project too? Any more details about the issue?

push-pop commented 3 years ago

If this is the line in question I'm not sure how there could be a null reference... image

GordeyChernyy commented 3 years ago

After restarting I have this singleton in the scene and everything works image

Next time there is no singleton: image

And after creating it manually I still have errors image

GordeyChernyy commented 3 years ago

image

push-pop commented 3 years ago

It kinda seems like this would be an issue with the Singleton class then? Like it's not getting cleaned up between runs so it isn't getting created again. Maybe there was a Unity API change?

I need to download 2020 and will try it to see what's up. Can you repro on a new 2020 project? Otherwise are you able to share your project possibly?

push-pop commented 3 years ago

What version of 2020 are you on?

GordeyChernyy commented 3 years ago

here is the repo (2020.3.0f1) https://github.com/GordeyChernyy/MVVMTest It is a copy of the original project I removed all assets from the Assets folder and the issue is still present. Steps to reproduce:

  1. open scene Assets/Samples/Unity-MVVM/1.1.4/MVVM Tests/MVVMTest.unity
  2. enter play mode
  3. exit play mode
  4. enter play mode again Expected behavior: you should see exceptions in the console and the scene will not work
push-pop commented 3 years ago

Another note I realized that my new samples aren't in there! No wonder no-one can figure out how to use 😆

GordeyChernyy commented 3 years ago

I see you have a Basic Usage folder I will try to import it directly from git

push-pop commented 3 years ago

Yes It does seem to be an issue with Singleton OnDestroy not getting called. I believe it is because of exceptions being thrown on the OnDestroy method. image

This is a really old sample. I think it won't be an issue. Going to update the sample in the package.json for 1.1.5

GordeyChernyy commented 3 years ago

I just imported Basic Usage to the project and it has the same behavior but I used these repo samples or do you have a newer version on OpenUPM?

push-pop commented 3 years ago

Hmm ok I'll try to dig in a little later. Thanks for reporting

GordeyChernyy commented 3 years ago

Thanks for looking into it! I like Basic Usage samples looks clear!

push-pop commented 3 years ago

Wow I've been digging in and this is a nasty bug. I'm still not 100% there.

It seems that the Singleton class I've been using from here is no longer working. https://wiki.unity3d.com/index.php/Singleton

It seems the m_ShuttingDown is not getting reset to false and so the singleton is returning null. This must be due to a change with 2020... I may need to ask on the forums.

I think perhaps it is the same thing causing the other issue where DataBindingConnection is not getting reset to null between runs in DataBinding.cs

push-pop commented 3 years ago

This was an issue with Domain Reloading. For some reason in the example project "Enter Play Mode Settings" was checked but not "Domain Reloading"

Unchecking "Enter Play Mode Settings" in Project Settings > Editor fixes this issue.

image