Scripts#
plupy.scripts: create a C# script file and attach compiled scripts to objects.
name = plupy.scripts.new("PlayerController")
obj = plupy.data.objects["Player"]
component = plupy.scripts.attach(obj, name)scripts.new(name: str, folder: str = "") -> str creates Scripts/<folder>/<name>.cs with an empty Script.Update method, compiles project scripts and returns the class name. The name is a unique ASCII C# identifier, not a namespace; keywords, device names and existing type/file names are rejected. folder is any path under Scripts ("Enemies/Bosses", created as needed), or write it into the name ("Enemies/Boss"). Scripts are found by class name wherever they are under Scripts, so folders are purely your arrangement; arrange them as you like. It requires an editable project. Call it outside plupy.edit: source creation is persistent and is not part of metadata rollback or Undo. A compilation failure reports the created path and errors; the source remains, and no attachment is made. Fix the code before attaching.
scripts.attach(obj: Object | ComponentGroup, name: str) -> Component attaches an existing compiled script by class name. It is equivalent to obj.components.add("script:" + name) and can be grouped in plupy.edit. It edits the explicit shared definition, preserves selection, and refuses a variant (edit its base explicitly). Undo removes the attachment, not source files. Multiple attachments are allowed where the component catalog permits them. There is no implicit per-placement script or new script datablock: the code is a C# source file, the component is owned by an object/group, and each runtime occurrence gets its own script instance.
Obtain with obj.components. Supports the collection lookup protocol. Lists components stored directly on this definition, including legacy script components and scripts that are currently unavailable. It does not flatten components contributed by group uses. Existing groups are accessible with plupy.data.of_type("componentGroup"); their components, props, inputs and pins edit the shared group explicitly.
class ScriptsUsage and examples
new#
new(name, folder='')Create Scripts/<folder>/Name.cs and compile it. Call outside edit; source survives Undo.
attach#
attach(obj, name)Attach an existing compiled script to an object datablock; one undoable edit.
Related types#
Collection · Component · ComponentGroup · Object · edit
Source#
- _live.py:1539