tufduck01 wrote:
And that last line causes problem for the Editor. It crashes after I rebuild, or I get this error in the log:
Quote:
[Core] Error: Can't load Resource from 'Data\Shmup\Scenes\GameScene.Scene.res', because an error occurred:
InvalidCastException: [A]Shmup.SharedData cannot be cast to [B]Shmup.SharedData. Type A originates from 'GamePlugin.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array. Type B originates from 'GamePlugin.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array.
CallStack:
at Shmup.GameScene.GameController.OnInit(InitContext context) in C:\Users\Andreas\Desktop\Shmups\Shmup\Source\Code\CorePlugin\GameScene\GameController.cs:line 25
at Duality.Resources.Scene.OnLoaded() in c:\projects\duality\Source\Core\Duality\Resources\Scene.cs:line 1128
at Duality.Resource.Init(Resource res) in c:\projects\duality\Source\Core\Duality\Resource.cs:line 445
at Duality.Resource.Load(Serializer formatter, String resPath, Action`1 loadCallback, Boolean initResource) in c:\projects\duality\Source\Core\Duality\Resource.cs:line 422
Anyone know what's causing this error?
This error is a tricky one. When Duality reloads core plugins on compile, it will serialize all the existing objects, discard them, put the old plugin binaries that are still in memory on a blacklist, and reload all the objects with types resolved to the new plugin. If an object someone can make it past the discard-and-reload barrier, that would cause exactly this kind of problem, where there is an invalid cast between two seemingly identical types.
It
seems like AppData and UserData are exempt from reload, which is definitely a bug to be fixed on Duality-side, and which is likely the culprit here. I'll take care of this.
tufduck01 wrote:
I have a class [t]SharedData whoose purpose is to store information that is shared between scenes.
tufduck01 wrote:
Should I store game global information in some other way?
In general, the way to go to store information that is shared between scenes is defining a
custom Resource to do that. Setting a difficulty level would actually be something to store in UserData, but when it comes to game-related stuff, like game rules or blueprints or things like that, I'd definitely recommend a custom Resource.
Anyway, a custom Resource would also be a workaround for the issue you had
Edit: Should be fixed in Duality 2.12.15 and upwards.