Accessing another client component from a client component

Ideally I’d be able to access the entity itself from within a client component, but that’s not defined (self._entity). But surely I should be able to access other client components in some manner?

Edit: And is there a reason self._entity is undefined by default in client components? Manually setting it in the Lua console in Debug Tools seems to work fine (I tried it with a ladder and teleporting that ladder, then calling the ladder component’s get_base() function).

@max99x Any insight on this if you have a moment?

Not sure why they don’t get an _entity by default. @linda might know.

1 Like

Try also adding the client component to “components” in the manifest in addition to the existing entry (“client_components”). Is this a base game component or a new component you’re modding in, by the way?

1 Like

I’m not sure if that will help, since the ladder component is specified in both components and client_components (and referring to the same Lua file), and its client version doesn’t have self._entity specified in-game.

I’m trying to mess around with building UI stuff: client_building, building_monitor, and active_building_renderer.

client_building has it’s own special building entity it looks like in self._building_active_entity. building_monitor self._entity should work, since it’s referenced in the activate code. And active_building_renderer isn’t a component, it’s a component renderer, but in the initialize code it does have the self._entity variable set, so I’m not sure why that particular file wouldn’t have the reference set.

Yeah, the problem is that I was trying to access the building_monitor (specifically the _on_building_progress_slow() function, which is being run by the server) from within the active_building (since I need some data from it for the active_building_renderer, which is presumably being run by the client), which, since I discovered were different entities, I was trying to bridge the gap through the client_building which creates the active_building entity and is presumably the client version of the building component since they share URI aliases.

At which point I discovered client_building doesn’t have an entity, so there’s no clear path for sending data from the building_monitor to the active_building_renderer, and that’s where I started noticing other components (like the ladder component) not having an entity defined in the client version, so I thought there might be a pattern.

Am I just completely wrong on how client_building operates? It looks in the code like it might be a singleton that manages all buildings from the client side and thus manages just a single active_building entity… but isn’t it being attached(/instantiated) to every entity with the stonehearth:build2:building component, whose URI is shared with the server version? And if it is a singleton, why are the URIs the same if they operate at completely different scopes in completely different ways compared to other same-URI components like ladder and portal that are really individual-entity-based?