Can anyone possibly shed light on what's going on here?
I have an EventSystem that takes in mouseEventEntity's that at the least have a ScreenPointComponent which holds a Vector3 position which gets the Input.mousePosition.
```c#
public void Initialize()
{
dragEntityGroup = inputContext.GetGroup(InputMatcher.AnyOf(
InputMatcher.DragSelectionMouseButtonDown,
InputMatcher.DragSelectionMouseButtonHeld
));
}
protected override void Execute(List<InputEntity> entities)
{
InputEntity mouseEventEntity = entities.SingleEntity();
ScreenPointComponent mousePosition = new ScreenPointComponent();
mousePosition.position = mouseEventEntity.screenPoint.position;
in the above code and proceeding
```c#
//example
if (mouseEventEntity.isLeftMouseButtonHeld
&& !mouseEventEntity.isLeftMouseButtonDown)
{
if (dragEntity.hasDragSelectionMouseButtonHeld)
{
dragEntity.ReplaceDragSelectionMouseButtonHeld(mousePosition);
if I dont specifically instantiate and set mousePosition as a new ScreenPointComponent and instead use mouseEventEntitiy.screenPoint the results are very odd:
again the only dfference is the first (desired) example creates a new Entity and assigns it an existing
component and the second uses the existing component. You can see it lags behind the cursor greatly especially at lower speeds.
Thanks for any assistance!
Hi, I think I need more context, are you doing this in a system? Are you using group events directly?
@sschmid yes sorry, this is within a system, I updated the code above to show where the dragEntityGroup is being instantiated and how the behavior is occuring within the System's Execute method.
I think I cannot help other than suggesting to debug and see with path your code takes. I see you're using a reactive system, but I don't see the trigger and filter, so it's hard for me to guess. You usually never instantiate components yourself because they are all managed and object pooled by Entitas for you. If it's possible for you, please share more of the system code (like trigger and filter)
@sschmid ok, I didn't think about Entitas needing to manage components, I believe I had copied this approach from one of the many example projects. Let me try extracting ScreenPointComponent to a separate interface so I'm no longer instantiating Components.
I'll add the Filter and Trigger as well.
@sschmid followup, I think I know what's happening but it raises another question.
In the System I call:
```c#
if (inputHandler.IsDrag(
dragEntity.dragSelectionMouseButtonDown.screenPoint,
mouseEventEntity.screenPoint
)) {
inputHandler.HandleDrag(dragEntity, mouseEventEntity);
}
which compares the distances between the `screenPoint (Vector3)` where dragging started and where the `mouseEventEntity.screenPoint` (current mouse position) is. Basically it seems like the `Add*Component` functions set components equal by reference rather than value?
```c#
dragEntity.AddDragSelectionMouseButtonDown(mouseEventEntity.screenPoint);
later when mouseEventEntity.screenPoint changes, the dragEntity.dragSelectionMouseButtonDown is equal to it. This causes them to fail the distance check and causes the visual lag when the selection Rect determines it doesn't need to update.
If it is set by reference and we aren't supposed to instantiate new Components is having a Component contain other Components an anti-pattern? I copied this from this example btw.
I'll close, definitely seems like some Component fields will result in them being set by reference rather than value.
I just clicked the link you posted, and I saw the component stores other components in fields. You should never do that. Always work with component values.
Do
inputHandler.IsDrag(
dragEntity.dragSelectionMouseButtonDown.screenPoint,
mouseEventEntity.screenPoint.value // <- value, not the component itself
I will see who added this example project and will let him/her know
Updated my repo to eliminate this awefulness :)