.vs
Assets
Library
APIUpdater
Artifacts
Bee
BuildPlayerData
PackageCache
com.unity.collab-proxy@2.5.2
com.unity.editorcoroutines@1.0.0
com.unity.ext.nunit@1.0.6
com.unity.feature.development@1.0.1
com.unity.ide.rider@3.0.31
com.unity.ide.visualstudio@2.0.22
com.unity.ide.vscode@1.2.5
com.unity.modules.ai@1.0.0
com.unity.modules.androidjni@1.0.0
com.unity.modules.animation@1.0.0
com.unity.modules.assetbundle@1.0.0
com.unity.modules.audio@1.0.0
com.unity.modules.cloth@1.0.0
com.unity.modules.director@1.0.0
com.unity.modules.imageconversion@1.0.0
com.unity.modules.imgui@1.0.0
com.unity.modules.jsonserialize@1.0.0
com.unity.modules.particlesystem@1.0.0
com.unity.modules.physics2d@1.0.0
com.unity.modules.physics@1.0.0
com.unity.modules.screencapture@1.0.0
com.unity.modules.subsystems@1.0.0
com.unity.modules.terrain@1.0.0
com.unity.modules.terrainphysics@1.0.0
com.unity.modules.tilemap@1.0.0
com.unity.modules.ui@1.0.0
com.unity.modules.uielements@1.0.0
com.unity.modules.umbra@1.0.0
com.unity.modules.unityanalytics@1.0.0
com.unity.modules.unitywebrequest@1.0.0
com.unity.modules.unitywebrequestassetbundle@1.0.0
com.unity.modules.unitywebrequestaudio@1.0.0
com.unity.modules.unitywebrequesttexture@1.0.0
com.unity.modules.unitywebrequestwww@1.0.0
com.unity.modules.vehicles@1.0.0
com.unity.modules.video@1.0.0
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0
com.unity.performance.profile-analyzer@1.2.2
com.unity.settings-manager@2.0.1
com.unity.test-framework@1.1.33
com.unity.testtools.codecoverage@1.2.6
com.unity.textmeshpro@3.0.6
com.unity.timeline@1.7.6
com.unity.ugui@1.0.0
com.unity.visualscripting@1.9.4
Documentation~
images
snippets
TableOfContents.md
index.md
vs-add-custom-event-node-trigger.md
vs-add-custom-event-node.md
vs-add-inspectable-attribute-custom-types.md
vs-add-node-to-graph.md
vs-add-remove-node-library.md
vs-add-remove-type-options.md
vs-add-subgraph.md
vs-add-triggers-data-graph.md
vs-add-variable-graph.md
vs-advanced-topics-intro.md
vs-aot.md
vs-attach-graph-machine.md
vs-basic-concepts.md
vs-capture-player-input-add-component.md
vs-capture-player-input.md
vs-capturing-player-inputs-new.md
vs-capturing-player-inputs-old.md
vs-configuration.md
vs-control-schemes.md
vs-control.md
vs-create-custom-drawer.md
vs-create-custom-node-add-docs.md
vs-create-custom-node-add-logic.md
vs-create-custom-node-add-ports.md
vs-create-custom-node-add-relations.md
vs-create-custom-node-attributes-reference.md
vs-create-custom-node-empty.md
vs-create-custom-node.md
vs-create-graph-assign-existing-gameobject.md
vs-create-graph-assign-new-gameobject.md
vs-create-graph-on-machine.md
vs-create-graph-project-window.md
vs-create-graph-unassigned-flow.md
vs-create-graph.md
vs-create-own-custom-event-listen-code.md
vs-create-own-custom-event-node-trigger-code.md
vs-create-own-custom-event-node.md
vs-create-own-custom-event-send-node.md
vs-create-restore-backups.md
vs-create-state.md
vs-creating-connections.md
vs-creating-transition.md
vs-custom-events.md
vs-custom-types.md
vs-debug-messages.md
vs-debugging.md
vs-developers-guide.md
vs-editor-script-issues.md
vs-events-reference.md
vs-events.md
vs-formula.md
vs-graph-machine-types.md
vs-graph-types.md
vs-groups.md
vs-input-nodes.md
vs-interface-overview.md
vs-live-edit-runtime.md
vs-live.md
vs-nesting-add-state-unit.md
vs-nesting-add-subgraph.md
vs-nesting-add-triggers-data-graph.md
vs-nesting-input-node.md
vs-nesting-nodes.md
vs-nesting-output-node.md
vs-nesting-state-unit-node.md
vs-nesting-subgraph-node.md
vs-nesting-subgraphs-state-units.md
vs-nodes-events-input-system-button.md
vs-nodes-events-input-system-float.md
vs-nodes-events-input-system-vector2.md
vs-nodes-events-on-button-input.md
vs-nodes-events-on-keyboard-input.md
vs-nodes-events-on-mouse-down.md
vs-nodes-events-on-mouse-drag.md
vs-nodes-events-on-mouse-enter.md
vs-nodes-events-on-mouse-exit.md
vs-nodes-events-on-mouse-input.md
vs-nodes-events-on-mouse-over.md
vs-nodes-events-on-mouse-up-button.md
vs-nodes-events-on-mouse-up.md
vs-nodes-reference.md
vs-nodes.md
vs-nulls.md
vs-open-graph-edit.md
vs-refactor-add-attribute.md
vs-refactoring.md
vs-relations.md
vs-script-graphs-intro.md
vs-scripts-reference.md
vs-self.md
vs-set-preferences.md
vs-state-graphs-intro.md
vs-states-reference.md
vs-sticky-notes.md
vs-time.md
vs-transitions.md
vs-types.md
vs-update.md
vs-using-custom-types.md
vs-variables-api.md
vs-variables-reference.md
vs-variables.md
vs-version-control.md
Editor
Graphics
Runtime
.npmignore.release
.signature
CHANGELOG.md
CHANGELOG.md.meta
Editor.meta
Graphics.meta
LICENSE.md
LICENSE.md.meta
README.md
README.md.meta
Runtime.meta
Third Party Notices.md
Third Party Notices.md.meta
ValidationConfig.json
ValidationConfig.json.meta
ValidationExceptions.json
ValidationExceptions.json.meta
package.json
package.json.meta
PackageManager
PlayModeViewStates
PlayerDataCache
ScriptAssemblies
Search
ShaderCache
SplashScreenCache
StateCache
UIElements
AnnotationManager
ArtifactDB
ArtifactDB-lock
BuildPlayer.prefs
BuildSettings.asset
EditorOnlyScriptingSettings.json
EditorOnlyVirtualTextureState.json
EditorSnapSettings.asset
EditorUserBuildSettings.asset
InspectorExpandedItems.asset
LastBuild.buildreport
LastSceneManagerSetup.txt
LibraryFormatVersion.txt
MonoManager.asset
SceneVisibilityState.asset
ScriptMapper
ShaderCache.db
SourceAssetDB
SourceAssetDB-lock
SpriteAtlasDatabase.asset
Style.catalog
expandedItems
ilpp.pid
Logs
Packages
ProjectSettings
UserSettings
obj
.vsconfig
Assembly-CSharp.Player.csproj
Assembly-CSharp.csproj
TM1.sln
Unity.CollabProxy.Editor.csproj
Unity.EditorCoroutines.Editor.csproj
Unity.Performance.Profile-Analyzer.Editor.csproj
Unity.PlasticSCM.Editor.csproj
Unity.Rider.Editor.csproj
Unity.Settings.Editor.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Model.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Mono.Reflection.csproj
Unity.TestTools.CodeCoverage.Editor.csproj
Unity.TextMeshPro.Editor.csproj
Unity.TextMeshPro.Player.csproj
Unity.TextMeshPro.csproj
Unity.Timeline.Editor.csproj
Unity.Timeline.Player.csproj
Unity.Timeline.csproj
Unity.VSCode.Editor.csproj
Unity.VisualScripting.Core.Editor.csproj
Unity.VisualScripting.Core.Player.csproj
Unity.VisualScripting.Core.csproj
Unity.VisualScripting.Flow.Editor.csproj
Unity.VisualScripting.Flow.Player.csproj
Unity.VisualScripting.Flow.csproj
Unity.VisualScripting.SettingsProvider.Editor.csproj
Unity.VisualScripting.Shared.Editor.csproj
Unity.VisualScripting.State.Editor.csproj
Unity.VisualScripting.State.Player.csproj
Unity.VisualScripting.State.csproj
Unity.VisualStudio.Editor.csproj
UnityEditor.TestRunner.csproj
UnityEditor.UI.csproj
UnityEngine.TestRunner.Player.csproj
UnityEngine.TestRunner.csproj
UnityEngine.UI.Player.csproj
UnityEngine.UI.csproj
81 lines
3.9 KiB
Markdown
81 lines
3.9 KiB
Markdown
![]() |
# Create a Custom Scripting Event node
|
||
|
|
||
|
You can create a Custom Scripting Event node with a C# script. With C#, you can customize all aspects of your Custom Scripting Event, unlike a Visual Scripting custom Event. For more information on the different types of custom Events, see [Custom Events](vs-custom-events.md).
|
||
|
|
||
|
To create a Custom Scripting Event node:
|
||
|
|
||
|
1. [!include[open-project-window](./snippets/vs-open-project-window.md)]
|
||
|
|
||
|
1. [!include[right-click-project](./snippets/custom-events/vs-right-click-project.md)]
|
||
|
|
||
|
1. [!include[create-c-script-project](./snippets/vs-create-c-script-project.md)]
|
||
|
|
||
|
1. Enter a name, such as `MyEventNode`, for the new script file.
|
||
|
|
||
|
1. Press Enter.
|
||
|
|
||
|
1. [!include[open-new-external-code](./snippets/vs-open-new-external-code.md)]
|
||
|
|
||
|
1. In your external editor, copy and paste the following code into the C# script:
|
||
|
|
||
|
```csharp
|
||
|
using Unity.VisualScripting;
|
||
|
using UnityEngine;
|
||
|
|
||
|
//Register a string name for your Custom Scripting Event to hook it to an Event. You can save this class in a separate file and add multiple Events to it as public static strings.
|
||
|
public static class EventNames
|
||
|
{
|
||
|
public static string MyCustomEvent = "MyCustomEvent";
|
||
|
}
|
||
|
|
||
|
[UnitTitle("On my Custom Event")]//The Custom Scripting Event node to receive the Event. Add "On" to the node title as an Event naming convention.
|
||
|
[UnitCategory("Events\\MyEvents")]//Set the path to find the node in the fuzzy finder as Events > My Events.
|
||
|
public class MyCustomEvent : EventUnit<int>
|
||
|
{
|
||
|
[DoNotSerialize]// No need to serialize ports.
|
||
|
public ValueOutput result { get; private set; }// The Event output data to return when the Event is triggered.
|
||
|
protected override bool register => true;
|
||
|
|
||
|
// Add an EventHook with the name of the Event to the list of Visual Scripting Events.
|
||
|
public override EventHook GetHook(GraphReference reference)
|
||
|
{
|
||
|
return new EventHook(EventNames.MyCustomEvent);
|
||
|
}
|
||
|
protected override void Definition()
|
||
|
{
|
||
|
base.Definition();
|
||
|
// Setting the value on our port.
|
||
|
result = ValueOutput<int>(nameof(result));
|
||
|
}
|
||
|
// Setting the value on our port.
|
||
|
protected override void AssignArguments(Flow flow, int data)
|
||
|
{
|
||
|
flow.SetValue(result, data);
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
1. [!include[save-script](./snippets/vs-save-script.md)]
|
||
|
|
||
|
1. [!include[return-unity](./snippets/vs-return-unity.md)]
|
||
|
|
||
|
1. [!include[regen-node-library](./snippets/vs-regen-node-library.md)]
|
||
|
|
||
|
1. [Open a Script Graph](vs-open-graph-edit.md) where you want to add your new node.
|
||
|
|
||
|
1. [!include[open-fuzzy-finder](./snippets/vs-open-fuzzy-finder.md)].
|
||
|
|
||
|
1. Go to **Events** > **My Events**.
|
||
|
|
||
|
1. Select your **On My Custom Event** node to add it to the graph.
|
||
|
|
||
|
> [!NOTE]
|
||
|
> If you change the `UnitTitle` or `UnitCategory` attributes for the node in your code, the node appears in the location in the fuzzy finder with the name that you specify.
|
||
|
|
||
|

|
||
|
|
||
|
After you regenerate your Node Library, the Custom Scripting Event node appears in the fuzzy finder. If you didn't change the `[UnitCategory]` or `[UnitTitle]` from the sample code, then the fuzzy finder displays the node under **Events** > **MyEvents**, as the **On my Custom Event** node. For more information on the fuzzy finder, see [The interface](vs-interface-overview.md#the-fuzzy-finder).
|
||
|
|
||
|
## Next steps
|
||
|
|
||
|
After you create your Custom Scripting Event node, you can [create a Custom Scripting Event Sender node](vs-create-own-custom-event-send-node.md) to trigger your Event from another Script Graph or location in the same Script Graph. You can also [create a script to trigger your Event from code](vs-create-own-custom-event-node-trigger-code.md) or [create a script to listen to your Event](vs-create-own-custom-event-listen-code.md).
|