Skip to content

CyanTrigger Program Asset

CyanLaser edited this page Jun 25, 2022 · 3 revisions

CyanTrigger Program Assets are asset files that contain CyanTrigger logic. They are very similar to the component version of CyanTrigger. When a CyanTrigger Program Asset is paired with a CyanTriggerAsset component, the creation experience is very similar to just a CyanTrigger component. The two are interchangeable and can be converted back and forth. The CyanTrigger Program Asset workflow is very similar to how UdonGraph programs are handled. The program must be first created before it can be edited. Once created, it can be reused on multiple objects. CyanTrigger components normally do this for you behind the scenes.

CyanTriggerProgramMirrorToggle

How To Create a CyanTrigger Program Asset

There are three ways to create a CyanTrigger Program Asset. After a CyanTrigger Program Asset has been created, you can click on the asset to show the same interface to create logic for your CyanTrigger.

Create From Assets Folder

Right click in your assets folder and select “Create/CyanTrigger/CyanTrigger Program Asset”

CyanTriggerCreateProgramAssets

Create From UdonBehaviour

On an UdonBehaviour without a program, use the program type dropdown to select “CyanTrigger Program Asset” and click “New Program”.

  • Note that the component must be in a saved scene to create the program. The button does not work when editing prefabs.
  • This will create a new program in a folder at the same location as the scene asset.
CyanTriggerCreateProgramUdon

Create From CyanTriggerAsset Component

Add the “CyanTriggerAsset” component to a GameObject, and click “New Program”.

  • Note that the component must be in a saved scene or prefab to create the program.
  • This will create a new program in a folder at the same location as the scene or prefab asset.
CyanTriggerCreateProgramCTA

CyanTriggerAsset Component

To use a CyanTrigger Program Asset, you must set this program in an UdonBehaviour or “CyanTriggerAsset” component. If you set it in an UdonBehaviour, it will give a warning to use a “CyanTriggerAsset” component.

CyanTriggerUdonWithoutCTA CyanTriggerCTASetProgram

The CyanTriggerAsset component is a custom inspector for CyanTrigger Program Assets. It provides many benefits over using just the UdonBehaviour component inspector:

View, Edit, and Lock Program

The CyanTriggerAsset component provides access to the CyanTrigger program. Viewing the program itself can be toggled on the CyanTriggerAsset. This will show the full program editor in the inspector just like what is displayed when you have the program asset selected. While the program is open and viewable, there is a warning to let you know that editing the program will edit everything that uses it. A lock button is provided to prevent editing, which will disable the program editors, but still allow viewing of all events and actions. The lock itself does not change anything about the program and is only there to help prevent making unwanted changes. The program can be locked and unlocked at any time. Program locking does not affect editing outside the CyanTriggerAsset.

When created through the “New Program” button in the CyanTriggerAsset, the program will be viewable and unlocked for editing. When created through other means, such as the create menu in the Assets folder, the program will be collapsed and locked in the CyanTriggerAsset.

CyanTriggerAssetEditLock

Multi-Editing

When two or more objects all have the CyanTriggerAsset component with the same program, then selecting all of them will allow you to multi edit the public variables. Variables with different values will be shown with an empty editor, but editing this will apply to all objects.

CyanTriggerAssetMultiEdit

Differences between CyanTrigger Component and Program Asset

Working with CyanTrigger Program Assets is very similar to working with CyanTrigger components. Here are some of the differences between the two:

CyanTrigger Component

  • Quick to add to objects and begin creating logic.
  • Only exist in the scene on GameObjects.
    • Can only be viewed and edited in the scene or prefab
    • Must make a prefab to share.
    • Can cause issues when editing CyanTrigger on prefabs
    • CyanTrigger in spawned prefabs will not work at all.
  • Component is individual and not linked with any other CyanTrigger component.
    • Editing one only edits that one and not any other in the scene.
  • Does not support multi-editing
  • Allows directly referencing Unity Objects in actions without needing to create variables.
  • Can only have one CyanTrigger per GameObject.
  • Will be recompiled on entering playmode and on world upload.

CyanTrigger Program Asset + CyanTriggerAsset Component

  • Requires its own file
    • Can be edited by clicking the asset. No need to load the scene
    • Can also be edited in the CyanTriggerAsset component in the scene or prefab
  • Must be used with UdonBehaviour or CyanTriggerAsset components to work in the scene.
  • Can be used multiple times on the same and different GameObjects
    • Updating the program updates everything that uses it..
  • Supports multi-editing if all have the same program.
  • Works with spawned prefabs.
  • Can be easily shared and used in other projects.
    • Provides a way to export to Udon Assembly so that it can be shared without dependencies on CyanTrigger scripts at all.
  • Can be used to create Custom Actions to make your own logic.
  • Cannot reference Unity objects directly and must use Variables set in the scene.
  • Only recompiles while editing.
    • Does not recompile on entering playmode or world upload.

When to use Program Asset over Component

Overall, working with CyanTrigger component may be faster for prototyping, but you should use CyanTrigger Program Assets for these cases:

  • The program is going to be reused on multiple objects
  • The program will be part of a prefab
  • If you want to package and distribute systems
  • You want to create a Custom Action

Converting between Program Asset and Component

While working, you are not locked into only using one type of CyanTrigger. Both CyanTrigger components and CyanTrigger Program Assets provide ways to convert to the other under the Utilities section.

Converting CyanTrigger Component to Program Asset

CTUtilities

On a CyanTrigger Component, expanding the Utilities will give the option to Convert to CyanTriggerAsset and Export to CyanTrigger Program. Both options will create a new program asset in the same directory as the scene or prefab. The Convert to CyanTriggerAsset will also remove the CyanTrigger component and add a CyanTriggerAsset component with the exported program. Since Program Assets can’t have GameObject or Component references in the program itself, it will ask how you want to convert them. There are two options on converting Unity Object references:

  1. Find all unique references, make a variable for those, and reuse that variable every time that object is used. This option will be more readable when editing the program.
  2. Make every reference its own new global variable.
ExportToProgramDialog

Converting CyanTriggerAsset to CyanTrigger Component

In order to convert a Program Asset to a CyanTrigger Component, you need to have a CyanTriggerAsset on the GameObject with the program you want to convert. Clicking the “Convert to Scene CyanTrigger” will remove the CyanTriggerAsset component and replace it with a CyanTrigger component with all the variables and events. Note that you can only have one CyanTrigger component on a GameObject, but you can have multiple CyanTriggerAsset components. Trying to convert a CyanTriggerAsset to a CyanTrigger when there is already a CyanTrigger on the GameObject will fail to convert.

Unity Objects and Variables

Unlike CyanTrigger components, CyanTrigger Program Assets cannot directly reference Unity Objects. This is a Unity limitation as you cannot reference scene objects and components outside the scene they exist in as well as CyanTrigger Program Assets can be used in multiple scenes. In order to use these objects, you must create variables to hold them.

CTAUtilities

Global Variable Options

When working with CyanTrigger Program Assets, you can set information on global variables to change how it will display in CyanTriggerAsset components. There are 3 main options that you can change.

CyanTriggerProgramMirrorToggle

Variable Groups

Groups are ways to keep similar variables together. You can add a Variable Group clicking on the folder button in the variable editor. Drag variables into the group to add them to the group. You can have variable groups within variable groups. Variable Groups are available to both CyanTrigger components and CyanTrigger Program Assets.

CyanTriggerAssetVariables

Variable Comments

Comments are ways to add information about a variable. The comment will be displayed above the variable’s name. You can add or edit a variable’s comment by right clicking on a variable and selecting “Edit Comment”. Variable Comments are available to both CyanTrigger components and CyanTrigger Program Assets.

RightClickVariableOptions

Hidden Variables

Variables will always be shown in CyanTrigger Program Assets, but you have control on if it should be shown in the CyanTriggerAsset component. You can right click a variable and select the Hide Variable option to hide it in the inspector. Hidden variables will appear slightly darker. You can also hide variable groups to hide all variables within it. Note that any variable that starts with two underscores, “__” will automatically be hidden.

Hiding variables only works in CyanTrigger Program Assets, as it will hide it in the CyanTriggerAsset component. Variables will always be shown on CyanTrigger components and the option to hide is disabled.

Clone this wiki locally