Components


LUNOS has been moving towards a more component based organization structure. This has massive advantages for code reuse and simplicity, but may take a bit getting used to. Let’s take a look at an example.

GridNodeComponent


Grid nodes can appear as a part (or component) of a wide variety of actors. Currently, there is the BP_StaticGridNode, as well as the node that appears on top of the pillars themselves. Child actors are nonsense garbage, so components are the next best thing.

We want the grid node component to encapsulate everything to the point that all we have to do is add the component to ANY actor and it will work as expected, visuals and all. We have to forgo a few nicities that actors provide and think a lil outside the box, but we can do it.

NOTE: I should really figure out how to incorporate those nifty online BP things.

{{0xc0008cbb30 0xc0008cbb30 image.png  alt text alt text 0xc000a30c60} 0 false}
In the component, we call this initialize function, which takes a look at its type and sets up some custom primitive data. Notice that in the case of the cane block, we actually spawn a new component on the owner - this is super powerful since despite components being unable to own subcomponents, we can sorta take over the owning actor and add stuff to it instead.

{{0xc0008cbb30 0xc0008cbb30 image-1.png  alt text alt text 0xc000a83b00} 1 false}
One extremely useful feature of components is that they contain their own tick function and can update completely independently from their owner. What makes this so powerful organizationally is that they can disable their own tick without affecting their owner. This tick updates the “glow” alpha linearly up or down depending on bOccupied, sends that value to CPD via UpdateAnimation, then does a simple check to see if the value capped out. If true, it turns it’s tick off, stopping the entire update function and saving cycles.

{{0xc0008cbb30 0xc0008cbb30 image-2.png  alt text alt text 0xc00075d9e0} 2 false}

Remember to set StartWithTickEnabled to false! You can also set a differnt update rate than the owner, which can also be very useful.

Unfortunately, timelines are unavailable in components as timelines themselves are components! This enforces a bit of optimization, but ultimately is worth it. You can still read curves as you can bring them in with a curve asset.