GetComponent function in python?

Is there a way to access another objects component using a script, in the bge?
In unity you can use something like:

GameObject.GetComponent

I basically just need a way to get a setting from another objects component into a script, not one from the object that is running the script.

Not sure what you mean by a “component”, but you can absolutely get other objects and access their properties, location, etc etc

Usually it’s most convenient to get them via some kind of interaction, like accessing the target from a collision sensor or ray sensor. Alternatively, you can look it up in the list of all objects in the scene, or just keep a reference to the object inside a global variable.

maybe you mean getting arguments from another component or local-global variables that another component uses? you can get an object through sensors-rays, radars, and collisions, or through rayCast you can get properties from the received object and change them - for example, for bullet damage-
ray = own. rayCast(own, enemy, 100,")
hit = ray[0]
if hit:
if ‘health’ in hit:
hit[‘health’] -= 10
or so
radar = cont. sensors [‘Radar’]
if radar.positive: obj = radar. hitObject
if ‘health’ in obj:
obj [‘health’]-=10

You mean in UPBGE? You can by accessing the list object.components.

1 Like

Yep, that worked! Thanks!