0 votes

I am using Godot+Mono and when I try to serialize an InputEvent using C# it crashes upon load or save


E 0:00:13.720   System.Reflection.MemberInfo[] System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(System.RuntimeType ): System.Runtime.Serialization.SerializationException: Type 'Godot.InputEventKey' in Assembly 'GodotSharp, Version=, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Load (error due to corrupted save file when it crashed during saving):

E 0:00:01.157   void System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run(): System.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed.

I got around this temporarily by creating my own SerializableInputEvent class that saves the keyboard scancode or the mouseindex and uses them to re-create the input event for input binding. Obviously this is a limited approach that fails on all other input types, defeating the purpose of input binding.

Ideally I'd like to remove this intermediary class, or at least make it work with all possible input events. Would it be possible to somehow convert the Godot.InputEvent to a blob and save that blob directly? I'd imagine this would be required functionality when sending IE's remotely for multi-player games, but I am having trouble figuring out how to do this. Any help is appreciated.

Godot version 3.2.3
in Engine by (693 points)
edited by

1 Answer

0 votes
Best answer

I used GD.Var2Bytes(inst,true) and (InputEvent)GD.Bytes2Var(b,true)

by (693 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.