Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Tips for a good balance between Visual Scripting and C#?

Discussion in 'Visual Scripting' started by kurroarashi, Mar 24, 2021.

  1. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    Self-explanatory question.

    Imo, UE4 seems to have a fairly clear line between what's better done in C++, and what's something you really should just stick to Blueprints about. Alex Forsyth did a good video on this.

    Despite knowing about Bolt acquisition since its announcement, I only recently started using Visual Scripting. What are some workflows that you recommend are better done in VS than in C#? Or are better done in synergy?

    On that topic, what are ways that you can synergize VS and C#? I know that you can directly call C# functions from VS by exposing the assemblies etc., but can you do it the other way around? Something akin to BlueprintNativeEvent/BlueprintImplementableEvent or Blueprints implementing a UInterface in UE4.

    (My question is not meant to be in a vacuum, I have a definite use-case if you can call a state graph or something from C#.)

    Anyway, even though I have specific questions, I really mean this to be a general discussion about how exactly programmers can get the most juice out of using VS and C# together.

    And if someone working on VS team is reading this, are there any plans to expose HPC# (Burst/Jobs) to VS?
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    1,763
    The current implementation of Unity Visual Scripting is almost entirely reflection based, so there's a performance implication - UVS is about 10-25 times slower than C# based on the scenario. They're working on a new, high performance runtime, but right now it's pretty slow.

    Which is why you wouldn't use UVS for anything performance intensive such as pathfinding, anything with Update really.

    There are several situations where a VS solution is preferable over C#. Such as level design related logic that doesn’t repeat elsewhere in the game. Or point n’ click adventure game hotspot scripting where each hotspot has its own dialogue, triggers, etc. It can also be great for prototyping in general since there’s 0 iteration time - you can build graphs in Play mode and immediately test them. No need to exit Play mode, re-compile, etc. - great for experimentation. UVS can also be used for some rudimentary state machine based AI, but this doesn’t scale due to performance constraints.

    As for synergy, it seems the current implementation of Unity Visual Scripting doesn’t appear to have any C# API documented - it’s in the process of being replaced with a new API that the high performance runtime will bring. Bolt 1.4 on the asset store does have some API documented for triggering Bolt’s custom events in a graph from C# scripts, however. But that API soon will be obsolete, since the asset store version is pretty much outdated at this point.

    The one C#/UVS synergy you can freely use right now is reflection. If you go to Project Settings/Visual Scripting (or in the case of 1.4 - Tools/Bolt/Unit Options Wizard) you can add your own scripts and assemblies there to expose them to UVS. After regenerating, UVS will grab all public variables, structs and methods from any C# scripts added there and show them in the fuzzy finder.

    Until the new runtime and API get here, that’s pretty much it as far as C#/UVS synergies go.
     
  3. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    Damn.. That doesn't sound very useful in its current state outside the scenarios you mentioned then (prototyping/one-offs), and performance-related scalability looks to be a major hurdle.

    I have gone through the UVS 1.5 documentation and you're right, there's practically no mention of a C# API that I could find.

    If it did, I had a really nice extension of my AI system in mind, where you could script a task in UVS and iterate quicker than usual.