Search Unity

How to set a component from a button click?

Discussion in 'Entity Component System' started by GarthSmith, Jul 23, 2018.

  1. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Hello!

    I want the ComponentSystem to set a ComponentData when a button is clicked. However, since OnUpdate() is not running, the system has no component group injected into it.

    My solution: The button click sets a private bool in the system. Next time OnUpdate is run, the system has the entity injected and the ComponentData gets set.

    This does not seem ECS-like as the system is now storing a bool.

    Is there some other way such a common task should be handled? Have I missed a tutorial that shows processing a simple UI Button click? Do you avoid the ComponentSystem completely and loop through every Entity until the desired one is found?

    Thanks for the help getting familiarized with Unity's ECS!