Events, variables and generated C#
Extend generated Unity event methods, typed variables, local scopes and built-in game actions without editing files that reimport overwrites.
Native conversion ยท importer 0.3.11
One method per event
A project event such as open_door becomes a readable public C# method such as OpenDoor() on <Project>Logic. The generated Awake connects scene references and component UnityEvents. on_start becomes OnStart(), invoked when GameManager begins play.
Local @ events are generated for their owner objects. RunIn preserves the current item scope for nested and delayed calls. An event that is not registered, or a local event with no listeners, remains an inactive branch rather than inventing behaviour.
Keep custom code in the user partial class
<Project>Logic.Generated.cs is regenerated. <Project>Logic.cs is created once and preserved. Put your own fields, methods and Unity messages in the user file, or use separate scripts under UserContent.
The following example is illustrative: replace ExampleLogic and OpenDoor with the class and event methods actually generated for your project.
using UnityEngine;
namespace ZimensionWorlds
{
public partial class ExampleLogic
{
partial void OnAwake()
{
// Add your own component connections here.
}
public void OpenDoorAfterTwoSeconds()
{
After(2f, () => OpenDoor());
}
}
}Variables and local scope
Project variables become typed properties on the generated logic class. Read and assign the generated property name rather than guessing the original JSON field name. Built-in player_health is read-only in the event model.
The protected LocalNumber(name), LocalBool(name), LocalText(name) and SetLocal(name, value) helpers access item-local variables in the current Scope. Use RunIn(item, action) when custom code needs to execute in an item's scope.
Useful protected helpers
| Helper | Purpose |
|---|---|
| After(seconds, action) | Delay an action while retaining the current local scope. |
| AfterOnce(key, seconds, action) | Restart a keyed delayed action rather than accumulating duplicates. |
| RunIn(item, action) | Temporarily establish the owning GameObject for local events and variables. |
| ClearDelays() | Cancel pending delayed callbacks on this logic component. |
| PlayAnimation(animator, state, fade) | Cross-fade the model Animator to a generated state. |
| PlayTransition(animator, state) | Start an object's baked movement state. Held weapons ignore placement transitions. |
| PlaySound(source), StopSound(source) | Control converted AudioSources. |
| Builtin(name) | Delegate a supported built-in event to GameManager. |
Built-in game actions
| Event | Unity behaviour |
|---|---|
| reset_player | Respawn the player at the current checkpoint or initial spawn. |
| reset_world / die_start_over | Reload the current scene. |
| player_dead / game_over_win | Apply player death or show the win screen. |
| launch_player_up_5m / launch_player_up_10m | Apply upward launch velocity. |
| reduce_health_10 / reduce_health_50 / increase_health_20 / full_health | Change player health. |
| scene_fade_in / scene_fade_out | Fade the default HUD. |
| freeze_player_movement / unfreeze_player_movement | Toggle the player's frozen flag. |
| increase_boost_20 / full_boost / stop_vehicle | Change boost or stop the currently mounted vehicle. |
| clear_delay_events | Cancel delayed generated logic callbacks. |
| save_game | Flush PlayerPrefs. This does not implement account-linked cloud saves. |
