Attention
You are viewing PyUnity docs under the develop
branch.
As such, they are only applicable if you installed from source.
Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent
release.
pyunity.files module¶
Source code: pyunity/files.py
Module to load files and scripts. Also manages project structure.
- class pyunity.files.Behaviour[source]¶
Bases:
Component
Base class for behaviours that can be scripted.
- Awake()[source]¶
Called every time a scene is loaded up, regardless whether the Behaviour is enabled or not. Cannot be an
async
function.
- async Start()[source]¶
Called every time a scene is loaded up. Only called when the Behaviour is enabled. Can be either a normal function or an
async
function.
- async Update(dt)[source]¶
Called every frame. Can be either a normal function or an
async
function.- Parameters:
dt (float) – Time since last frame, sent by the scene that the Behaviour is in.
- async FixedUpdate(dt)[source]¶
Called every frame, in each physics step. Can be either a normal function or an
async
function.- Parameters:
dt (float) – Length of this physics step
- async LateUpdate(dt)[source]¶
Called every frame, after physics processing. Can be either a normal function or an
async
function.- Parameters:
dt (float) – Time since last frame, sent by the scene that the Behaviour is in.
- async OnPreRender()[source]¶
Called before rendering happens. Can be either a normal function or an
async
function.
- class pyunity.files.Scripts[source]¶
Bases:
object
Utility class for loading scripts in a folder.
- template = 'from pyunity import *\n\nclass {}(Behaviour):\n async def Start(self):\n pass\n\n async def Update(self, dt):\n pass\n'¶
Type:
str
- static CheckScript(text)[source]¶
Check if
text
is a valid script for PyUnity.Notes
This function checks each line to see if it matches at least one of these criteria:
The line is an
import
statementThe line is just whitespace or blank
The line is just a comment preceded by whitespace or nothing
The line is a class definition
The line has an indentation at the beginning
These checks are essential to ensure no malicious code is run to break the PyUnity engine.
- static LoadScript(path, force=False)[source]¶
Loads a PyUnity script by path.
- Parameters:
path (Pathlike) – A path to a PyUnity script
force (bool) – Continue on error
- Returns:
The compiled PyUnity script
- Return type:
Notes
This function will add a module to
sys.modules
that is calledPyUnityScripts
, and can be imported like any other module. The module will also have a variable called__pyunity__
which shows that it is from PyUnity and not a real module. If an existing module namedPyUnityScripts
is present and does not have the__pyunity__
variable set, then a warning will be issued and it will be replaced.
- class pyunity.files.Asset[source]¶
Bases:
SavesProjectID
- class pyunity.files.Skybox[source]¶
Bases:
object
Skybox model consisting of 6 images
- points = [-1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1]¶
Type:
list
- class pyunity.files.Prefab[source]¶
Bases:
Asset
Prefab model
- Instantiate(scene=None, parent=None, position=Vector3(0, 0, 0), rotation=Quaternion(1, 0, 0, 0), scale=Vector3(1, 1, 1), worldSpace=False)[source]¶
Instantiate this prefab.
- Parameters:
scene (Scene, optional) – The scene to instantiate in. If None, the current scene is selected.
parent (GameObject, optional) – The parent to instantiate the Prefab under. If None, the prefab will be instantiated at the root of the scene.
position (Vector3, optional) – Position of the newly created GameObject, by default Vector3.zero()
rotation (Quaternion, optional) – Rotation of the newly created GameObject, by default Quaternion.identity()
scale (Vector3, optional) – Scale of the newly created GameObject, by default Vector3.one()
worldSpace (bool, optional) – Whether the above 3 properties are world space or local space, by default False
- Returns:
The newly created GameObject
- Return type:
- Raises:
PyUnityException – If
scene
is None but no scene is running