Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get CGVolume from CGDataReference
#1
Hi I'm working on a game which uses a series of extruded volumes to form a course. I want to know where the player is along the whole course so I am adding a reference to each volume as a `CGDataReference` with the attribute `[CGDataReferenceSelector(typeof(CGVolume))]`. I want to get the actual `CGVolume` object from these so that I can get the `Length` property from each one. I am trying to do `var volume = dataRef.GetData<CGVolume>()` but this comes back null. How can I get the actual volume data in my Monobehaviour?
Reply
#2
Hi,
The following script worked for me. Does it work for you?

Code:
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Generator;
using UnityEngine;

public class test : MonoBehaviour
{
    [CGDataReferenceSelector(
        typeof(CGVolume)
    )]
    public CGDataReference Volume = new CGDataReference();

    void LateUpdate()
    {
        Debug.Log(Volume.GetData<CGVolume>().Length);
    }
}

Note that this script uses LateUpdate, and not Update, to ensure that the generator gets the time to update first. You can achieve the same effect by setting the execution order of your scripts.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
My code currently looks like this:
Code:
[CGDataReferenceSelector(typeof(CGVolume), Label = "Volume/Path_1"), SerializeField]
public CGDataReference path = new CGDataReference();

void Start() {
    if (path == null || path.IsEmpty) return;
   
    var vol = path.GetData<CGVolume>();
    Debug.Log("vol:  " +vol);
}

in the console I see:

Code:
vol is null?: True
NullReferenceException: Object reference not set to an instance of an object.

Oh wait, I see your comment about `LateUpdate` now. I added a frame delay before trying to get the volume and now it works!
Reply
#4
Glad to hear that.
If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Forum Jump: