Entitas-csharp: How do I make changes to components?

Created on 22 Apr 2017  路  6Comments  路  Source: sschmid/Entitas-CSharp

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?

question

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.

#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.

All 6 comments

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).

  1. Move Components, Systems and GameController.cs to a folder outside your project (e.g. desktop). Or create a folder called "StreamingAssets" in your assets folder and move them to here (Unity will not compile the code in this folder) .
  2. Delete the contents of your Generated folder
  3. Regenerate contexts (ctrl-shift-G)
  4. Move Components folder back
  5. Make changes to your components
  6. Regenerate components (ctrl-shift-G)
  7. Move Systems and GameController.cs back and you're done.

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.

Entitas on the Asset Store

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamesMcMahon picture JamesMcMahon  路  5Comments

yanjingzhaisun picture yanjingzhaisun  路  4Comments

Noicon picture Noicon  路  4Comments

KumoKairo picture KumoKairo  路  3Comments

FNGgames picture FNGgames  路  5Comments