Issues with portal

Hello I have been taking part in the RPG course and I have seem to hit a roadblock which I have only just noticed at this moment, I am not sure where this bug has came from. It seems to be pointing to the save system but the problem is happening when I attempt to enter my portal, I believe this action is calling the saving system

BlockquoteSerializationException: Type 'GameDevTV.Utils.LazyValue1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers (System.RuntimeType type) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.Serialization.FormatterServices+<>c__DisplayClass9_0.<GetSerializableMembers>b__0 (System.Runtime.Serialization.MemberHolder _) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Collections.Concurrent.ConcurrentDictionary2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.FormatterServices.GetSerializableMembers (System.Type type, System.Runtime.Serialization.StreamingContext context) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize (System.Object obj, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.Formatters.Binary.ObjectWriter objectWriter, System.Runtime.Serialization.SerializationBinder binder) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize (System.Object obj, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.Formatters.Binary.ObjectWriter objectWriter, System.Runtime.Serialization.SerializationBinder binder) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo typeNameInfo) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArrayMember (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo arrayElemTypeNameInfo, System.Object data) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo memberObjectInfo) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo typeNameInfo) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize (System.Object graph, System.Runtime.Remoting.Messaging.Header inHeaders, System.Runtime.Serialization.Formatters.Binary.__BinaryWriter serWriter, System.Boolean fCheck) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header headers, System.Boolean fCheck) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header headers) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) (at <695d1cc93cca45069c528c15c9fdd749>:0)
RPG.Saving.SavingSystem.SaveFile (System.String saveFile, System.Object state) (at Assets/Scripts/Saving/SavingSystem.cs:64)
RPG.Saving.SavingSystem.Save (System.String saveFile) (at Assets/Scripts/Saving/SavingSystem.cs:30)
RPG.SceneManagement.SavingWrapper.Save () (at Assets/Scripts/SceneManagement/SavingWrapper.cs:32)
RPG.SceneManagement.Portal+d__8.MoveNext () (at Assets/Scripts/SceneManagement/Portal.cs:36)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)

You are trying to save the LazyValue. The LazyValue is not serializable which is why you get this error. You should only save the value. Look for everywhere you are saving (CaptureState) a LazyValue and make sure you store <variable>.value and not the variable.

    public object CaptureState()
    {
        return currentWeapon.value.name;
    }

could this be the issue in that case as its the only one with .value in CaptureState?
so in this case it would be currentWeapon.value?

The problem is that it does not have .value in CaptureState but it should.

Find every variable that is a LazyValue. For instance in the Health class (Health.cs) we store the health value in a LazyValue. Once you have those, check CaptureState and make sure you use health.value and not just health

Hereā€™s the sample from my code:

private LazyValue<float> _health;

...

public object CaptureState()
{
    return _health.value;
}
1 Like

OMG Is it wrong for me to say I love you right now XD you didnā€™t even look at my code yet knew where the issue was!
Master Problem Solver is correct, I appreciate you and all your help!
my question now would be, in the example we didnā€™t use _health we used healthPoints instead, I know it is meant to be good practice to place variables with _, is there a reason for this ?

Itā€™s just the C# standard practice and I use it daily at my job, so Iā€™m used to it. We donā€™t use every single convention, but weā€™re pretty close.

You can find it here.

The underscore;

When I see this I immediately know that this variable is private (or internal) and it belongs to the class

oh so does that mean its just conventional for allowing other programmers to tell which field is private then. Thank you again for your support!

Yeah, the conventions help with readability. When you know the convention it becomes easier to know the scope of things, etc. without having to scroll around through code trying to figure it out.

1 Like

My least favorite rule (though I use it when convention requires it).
I prefer camelCase for private, and PascalCase for properties/public variables (and I do not use public variables).

Itā€™s more than that. Style conventions apply to how methods and properties are named, indentation rules, whether the { is right after the method name :::shudder::: or on the next line, and more.

Most companies will either adopt the suggested Microsoft C# formatting guidelines or will have their own internal set of guidelines. We donā€™t have to worry about this in our own personal projects much, except that for future readability, itā€™s a GOOD idea to adopt a set of guidelines and stick with it. If youā€™re using a code editor like Microsoft Visual Studio Community (free, but not VS Code) or JetBrains Rider (not free!), the editor will note when things donā€™t follow the proper style guidelines. You can even tell those programs what your style guidelines are!

When working in groups, these guidelines become vital. Just because you wrote the class, it doesnā€™t mean youā€™ll necessarily be the one maintaining the class going forward. You might not even work for the company next week (because you got a better job at another company). By sticking to guidelines, the codebase is easier to maintain for everybody. If you try to push code that doesnā€™t follow the guidelines, in some companies, it might not pass code review from the companyā€™s QA department (and yep, that happened to me once).

1 Like

Personally, I am quite fond of the underscore. I didnā€™t initially like it but I suppose years of its use made it part of me

Ditto. I despise these.

:::shudder:::

The _ I can live with, especially when working on others codeā€¦
The placement of the { is non-negotiableā€¦ Iā€™ll die on that hill. To me itā€™s a matter of readabilityā€¦

public void foo() {
    bar();
}

:::shudder:::

public void foo()
{
    bar();
}

Serenity.

My brain also goes crazy when students forget to use the ``` and format their codeā€¦ Iā€™ve been known to use my Moderator powers to fix those posts and format the codeā€¦

For this, I will share a clip from Unite Austin 2017
https://youtube.com/clip/UgkxedigSaPqeNDIEsoNCxzEl5dnJdjNXJBT

If only you knew how many times I wished I had that powerā€¦ I had a brief few months of ā€˜regularā€™ status (December holiday robbed me of that, but Iā€™ll get it back) and I could fix mis-categorised posts because it is also quite irritating opening a post here and seeing an Unreal Engine question. I donā€™t mind UE but I canā€™t answer the questions because I am not well versed in ā€˜The Art of he Unrealā€™.

The first time I saw that, I howled in laughter. Thatā€™s actually a very informative talk, but my favorite part is that ā€œbecause weā€™re not monstersā€ line.

Ah funny enough I have been becoming one of those monsters XD I figured it would be neater having the curly braces on the same line, maybe I will revert back to having them start on new linesā€¦ I thought this was bad practice due to more lines in the code. I can see how this could become confusing though.

I will attempt to implement this in the future maybe when I have completed the course and continue my intended project I will go back and change the private and internal variables over to _camelCase and make sure all methods. I will also revert back from placing my curly braces on the same lines as their methods, I donā€™t intend to make eyes bleed.

Privacy & Terms