slash-framework
slash-framework copied to clipboard
Deleted Component cause error for the blueprints editor
Correct me if I'm wrong, I thought the advantage of the ECS is that if I want to delete a feature, I just need to delete the folder. But I notice that when I renamed a certain component, it causes the blueprint editor to fail to open. And I need to open the XML file to delete the component from the entities it attaches with to make the editor working again. Is there a way, maybe a new feature that once a component is missing, the entity blueprints just automatically detach the component? Good idea? ;) Bad idea? :o
Hi Don, It's okay that there is some kind of warning if you delete a component that is still used by a blueprint. But it should still be possible to open the blueprint editor anyway. So I will have a look at it :) Automatically detaching it is not the best idea, because a dev may think that a component isn't used anymore, deletes it and doesn't realize immediately that a blueprint was still using it. There should be at least a warning about it.
I can confirm that an exception is thrown
TypeLoadException: Unable to find type Slash.Examples.HelloWorld.Components.PositionComponent. Slash.Reflection.Utils.ReflectionUtils.FindType (System.String fullName) (at Assets/SlashFramework/Slash.Reflection/Utils/ReflectionUtils.cs:62) System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10
2[System.String,System.Type].MoveNext () System.Collections.Generic.List
1[System.Type].AddEnumerable (IEnumerable1 enumerable) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:128) System.Collections.Generic.List
1[System.Type]..ctor (IEnumerable1 collection) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:65) System.Linq.Enumerable.ToList[Type] (IEnumerable
1 source) Slash.ECS.Blueprints.Blueprint.set_ComponentTypesSerialized (System.String[] value) (at Assets/SlashFramework/Slash.ECS.Blueprints/Blueprint.cs:122) Slash.ECS.Blueprints.Blueprint.ReadXml (System.Xml.XmlReader reader) (at Assets/SlashFramework/Slash.ECS.Blueprints/Blueprint.cs:311)
The question is how the case should be handled that a component type doesn't exist anymore when the blueprint xml is loaded.
Requirements for a solution:
- The user is informed about the missing type, otherwise a component may be removed by accident
- The blueprint editor is still usable and the component can be removed there if it is really not necessary anymore
Therefore the blueprint editor has to work without the types, but with the serialized type names.
Adjusting the Blueprint class would mean that it had to store a list of type names as well as the list of the component types. But the list of type names is only required in the editor and shouldn't be loaded at runtime.
This means we need a separate data class (BlueprintData?) which is used for the editor and for the serialization/deserialization. A positive side effect would be that this class could be used for Json serialization as well.