"Extending" built-in components on Actors #2895
-
I've been attempting to implement my own physics system. Thanks to ECS it's been straight forward to swap out the Motion & Collision systems with my own. This lets me still make use of Actor's built-in components such as body and collider, which is great! That is, until I inevitably need to extend either of those components with some custom behaviour to supplement the system, and this has put me in a bit of a pickle. Consider this scenario: I want to add a set of raycasts pointing in each direction to aid in collision solving for my physics system. I could make a new separate component, but I'd like to leverage the existing I could compose my own actor, but taking a peak at the default one shows there's a lot to replicate there. I thought about copying & pasting this into my own, but it uses an internal I thought maybe I could replace the body component with my own: class MyBodyComponent extends ex.BodyComponent {}
class MyActor extends ex.Actor {
constructor() {
super({})
this.removeComponent('ex.body')
this.addComponent(new MyBodyComponent())
}
public get body() { // <- called by super() before I've added it in my constructor
return this.get(MyBodyComponent)
}
}
So at this point I've had to settle with mutating the class MyActor extends ex.Actor {
constructor() {
super({})
extendBody(this.body)
}
}
extendBody(body) {
body.myCustomProperty = 123
} Any suggestions on how else this could be approached? I feel like composing my own Actor is the way to go here. If so, I wonder if there's a middle ground here between a bare entity and a custom Actor that Excalibur could offer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
We spoke in discord, and I think that ultimately we'll need to update Actor to use references to the components and not getters to allow users to override. |
Beta Was this translation helpful? Give feedback.
We spoke in discord, and I think that ultimately we'll need to update Actor to use references to the components and not getters to allow users to override.