Visual Script to C#

Does anybody know how can I turn this graph to pure C#?
And is there a way to auto convert graphs to C# scripts?
Thanks everyone.

Which part do you need help with?

I dont know. Did you try googling “ unity c# converter”?
If that doesnt come up with anything, probably not.

I’ve never dabbled with VisualScript but I guess it is translated to C# internally.

ChatGPT (specifically the paid GPT-4 with the Link Reader plugin) can analyze images:

GPT-4

The image you provided contains a visual script from Unity, which appears to be a flow of actions or events. Unfortunately, the Optical Character Recognition (OCR) result is not very clear, and it seems to have misinterpreted some of the text in the image.

However, I’ll try to provide a general idea of how this could be translated into C# based on the OCR result and my understanding of Unity’s API. Note that this might not be accurate due to the unclear OCR result.

using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class YourClass : MonoBehaviour
{
    public ARRaycastManager arRaycastManager;
    public UnityEngine.UI.Text debugText;

    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            List<ARRaycastHit> hits = new List<ARRaycastHit>();
            if (arRaycastManager.Raycast(touch.position, hits, TrackableType.Planes))
            {
                // Do something with the hit results
                // For example, you can print the hit position to the debug text
                debugText.text = hits[0].pose.position.ToString();
            }
        }
    }
}

This script assumes that you have an ARRaycastManager and a Text component attached to your GameObject. It checks for touch input every frame, and if there is a touch, it performs a raycast from the touch position. If the raycast hits a plane, it sets the debug text to the hit position.

Please replace YourClass with the appropriate class name for your use case. Also, ensure that the arRaycastManager and debugText are assigned in the Unity inspector or via script.

Remember, this is a very rough translation and might not accurately represent the visual script in the image. You may need to adjust it based on your specific needs and the actual content of the visual script.

3 Likes

Sorry for the necroposting, but I came here from Google and wanted to help the people looking for a solution like me. Following Ryiah suggestion, I just used Claude for the task and it works great. You open the graph asset with notepad, and copy the content (it will be a big YAML file). Then go to Claude and ask it if it can convert a Unity Visual Scripting graph into a C# script. It will say “yes, give me the graph”. Paste the big YAML file you copied and voilà, it will return for you the C# script. Worked like a charm for me. I hope this helps

1 Like