UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.43k stars 180 forks source link

ModuleNotFoundError: No module named 'bge' #1773

Closed wetoo-cando closed 1 year ago

wetoo-cando commented 1 year ago

Hello,

When I try to import bge from the python console in UPBGE, I get the ModuleNotFoundError:

>>> import bge
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
ModuleNotFoundError: No module named 'bge'

Does anyone know why this is happening?

In general, I am trying to use the uplogic add-on https://github.com/UPBGE/uplogic/, and it contains a number of bge imports.

Thanks!

BluePrintRandom commented 1 year ago

to use bge python you have to call it in game using a script node or a py component

wetoo-cando commented 1 year ago

Thanks @BluePrintRandom , the python component works. Sorry, I am new to blender. What do you mean by "script node"? A node in the uplogic-sense?

IzaZed commented 1 year ago

there's a "python code" node in the logic nodes addon, either that or the logic brick python controller

wetoo-cando commented 1 year ago

Ok, thanks @IzaZed

youle31 commented 1 year ago

bge is a python module which is only initialized AFTER bge start then it is not available before you launch the game engine. Scripts using bge can be used from a python controller logic brick, a python component, or python node if you are using logic nodes addon.

wetoo-cando commented 1 year ago

@youle31 Thank you for the explanation.