How do I make changes to components?
I had a component and I wanted to change it:
public sealed class ViewComponent : IComponent {
public GameObject gameObject;
}
to
public sealed class ViewComponent : IComponent {
public Transform tr;
}
But I got a lot of compiler errors, although I fixed the code of all the systems.
I also tried to remove the generated code and generate it again, but without success
How to correctly change the members of a component?
Upcoming changes to the code generator will likely improve this in future, but for now, here is the process I use when i change my components (e.g. renames, new fields, deletions etc).
You may have compile errors at this point, caused by your component changes, but they won't be in generated code, they'll be in your systems code which you are now free to go and fix.
Between each of these steps make sure you allow Unity to compile. The code generator will not run with compile errors present or during Untiy compilation.
@boris-741
The only thing you have to do besides fixing the code in systems (what you already did) is fixing the generated GameViewComponent (assuming your context is called game). The AddView and ReplaceView methods have to be updated to accept Transform instead of GameObject. No need to move files out of the project or sth like that. Deleting the generated folder will never help as the code generator cannot pick up any changes if there are compile errors.
@FNGgames is right, with the new roslyn code generator, it will be way better, since all you have to do is generate again and you should be fine.
Also see the wiki about fixing compile errors
https://github.com/sschmid/Entitas-CSharp/wiki/Code-Generator#fixing-compilation-errors
@FNGgames I think your suggested workflow only works if components don't have any dependencies on you game code. As soon as a component uses a custom type in a field, it is getting more complicated. I think updating the generated code might be simpler
@sschmid All the code my components depend upon sit in my libraries folder next to the Entitas install, and I don't move it. If I use an enum for my componet, i declare it next to the component. I guess there's plenty of cases where this wouldn't be the case for people though.
In my project I have been using some defines that I can set to disable all my Entitas code when making changes to components or systems.
It is a bit of extra work, but has has helped with refactoring and Entitas upgrades. I disable Systems while refactoring Components. Then after I regenerate the new components, I can enable systems again. It seemed a bit nicer than moving code in and out of the project.
#if !MYGAME_DISABLE_ENTITAS_COMPONENTS
public sealed class ViewComponent : IComponent {
public GameObject gameObject;
}
#endif
And also one for systems.
#if !MYGAME_DISABLE_ENTITAS_SYSTEMS
public sealed class CommandLogicSystems : Feature {
// ...
}
#endif
I added those defines to my Entitas source file templates to keep it easy.
The new code generator is available. This will hopefully solve all your issues.
Most helpful comment
In my project I have been using some defines that I can set to disable all my Entitas code when making changes to components or systems.
It is a bit of extra work, but has has helped with refactoring and Entitas upgrades. I disable Systems while refactoring Components. Then after I regenerate the new components, I can enable systems again. It seemed a bit nicer than moving code in and out of the project.
And also one for systems.
I added those defines to my Entitas source file templates to keep it easy.