Runtime VFXParameterBinder

Hey all,

I’m working on a project where body joints get instantiated into the scene as they are identified (Orbbec Astra).
I’m trying to write a script that will add each joint as a position “Target” within the multiple position binder. I’m having trouble finding a way to reference this Targets list at runtime. I am on version 2019.2.17f1, vfx graph 6.9.2 and am not sure how to include UnityEngine.VFX.Utility

Has anyone tried this, or have knowledge of how I could do this? Thanks in advance!

Here’s what I have so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.VFX;
//using UnityEngine.Experimental.VFX.Utility - how to include?

public class VFXDynamicPositionBinder : MonoBehaviour
{

    public GameObject groupToWatch;
    VisualEffect vfxGraph;
 

    // Start is called before the first frame update
    void Start()
    {
        vfxGraph = gameObject.GetComponent<VisualEffect>();
    }

    // Update is called once per frame
    void Update()
    {
        BindChildrenToVFX();
    }

    public void BindChildrenToVFX()
    {
        var i = 0;
        foreach (Transform child in groupToWatch.transform)
        {
            i++;
            vfxGraph.SetInt("JointCount", i);
            Debug.Log(vfxGraph.GetInt("JointCount"));
            //set each child as a target in vfxparameterbinder
        }
    }
}

If anyone else was wondering how to ‘watch’ a GameObject for newly instantiated children & add to the Targets list, here’s how I managed. This may not be the right way but worked for me.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.VFX;
using UnityEngine.Experimental.VFX.Utility;


public class VFXDynamicPositionBinder : MonoBehaviour
{

    public GameObject groupToWatch;
    VisualEffect vfxGraph;
    VFXMultiplePositionParameterBinder parameters;

    // Start is called before the first frame update
    void Start()
    {
        vfxGraph = gameObject.GetComponent<VisualEffect>();
        parameters = gameObject.GetComponent<VFXMultiplePositionParameterBinder>();
    }

    // Update is called once per frame
    void Update()
    {
        BindChildrenToVFX();
    }

    public void BindChildrenToVFX()
    {
        parameters.Targets = new GameObject[groupToWatch.transform.childCount];

        for (var i = 0; i < groupToWatch.transform.childCount; i++)
        {
            var child = groupToWatch.transform.GetChild(i);
            parameters.Targets[i] = child.gameObject;
            parameters.UpdateBinding(vfxGraph);
        }
    }
}