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¶

Module to load files and scripts. Also manages project structure.

pyunity.files.convert(type, list)[source]

Converts a Python array to a C type from .

Parameters
• type (_ctypes.PyCSimpleType) – Type to cast to.

• list () – List to cast

Returns

A C array

Return type

class pyunity.files.Behaviour[source]

Bases:

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 () – 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 () – 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 () – 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.

async OnPostRender()[source]

Called after rendering happens. Can be either a normal function or an async function.

OnDestroy()[source]

Called at the end of each Scene. Cannot be an async function.

class pyunity.files.Scripts[source]

Bases:

var = {}

Type:

static CheckScript(text)[source]

Check if text is a valid script for PyUnity.

Parameters

text () – List of lines

Returns

If script is valid or not.

Return type

Notes

This function checks each line to see if it matches at least one of these criteria:

1. The line is an import statement

2. The line is just whitespace or blank

3. The line is just a comment preceded by whitespace or nothing

4. The line is a class definition

5. 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 GenerateModule()[source]

Loads a PyUnity script by path.

Parameters

path (Pathlike) – A path to a PyUnity script

Returns

The module that contains all the imported scripts

Return type

ModuleType

Notes

This function will add a module to sys.modules that is called PyUnityScripts, 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 named PyUnityScripts 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:

GetAssetFile(gameObject)[source]
SaveAsset(ctx)[source]
class pyunity.files.Texture2D[source]

Bases:

Class to represent a texture.

Loads the texture and sets up an OpenGL texture name.

setImg(im)[source]
use()[source]

Binds the texture for usage. The texture is reloaded if it hasn’t already been.

GetAssetFile(gameObject)[source]
SaveAsset(ctx)[source]
classmethod FromOpenGL(texture)[source]
class pyunity.files.Skybox[source]

Bases:

Skybox model consisting of 6 images

names = ['right.jpg', 'left.jpg', 'top.jpg', 'bottom.jpg', 'front.jpg', 'back.jpg']

Type:

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:

compile()[source]
use()[source]
class pyunity.files.Prefab[source]

Bases:

Prefab model

Contains(obj)[source]
Instantiate(scene=None, position=None, rotation=None, scale=None, worldSpace=False)[source]
GetAssetFile(gameObject)[source]
SaveAsset(ctx)[source]
class pyunity.files.ProjectSavingContext[source]

Bases:

class pyunity.files.File[source]

Bases:

pyunity.files.checkScene(func)[source]
class pyunity.files.Project[source]

Bases:

property assets
Write()[source]
ImportFile(file, write=True)[source]
ImportAsset(asset, gameObject=None, filename=None)[source]
SetAsset(file, obj)[source]
static FromFolder(folder)[source]