What's a good way to manipulate Selected Data with C# scripts? I'm having a hard time figuring out the exact syntax. Let's assume we're working with the Weapon Upgrade NPC tutorial. If I select my right hand weapon and assign it the key "weapon" and then call a function in a later step, how can that function find that weapon instance? Please provide a syntax example.
In particular I can't seem to access the member functions for the SelectedDataHandler. I can get the member functions of the SelectedDataHelper, but they give me entire lists when I'm looking for the single instance.
That's because a selected data key can contain multiple different things, so the SelectedDataHelper only has functions to get lists of things.
You can simply access whatever is stored in a key like this: object data = dataHandler.Get("key"); dataHandler is a SelectedDataHandler instance.
Since data could be anything, you'd have to check what it is, or directly do it like this: EquipShortcut equip = dataHandler.Get("key") as EquipShortcut equip would be null if it isn't an instance of EquipShortcut.
Otherwise, use the helper class, e.g.: List<EquipShortcut> equipment = SelectedDataHelper.GetEquipment(dataHandler.Get("key"));
Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found. If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Well, that's a bit tricky, since the selected data is only available/alive in the running event ... It'd be probably the easiest solution to write a custom node that just forwards the selected data to whatever script you need it in :)
Post edited by gamingislove on
Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found. If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
I can get the member functions of the SelectedDataHelper, but they give me entire lists when I'm looking for the single instance.
You can simply access whatever is stored in a key like this:
object data = dataHandler.Get("key");
dataHandler is a SelectedDataHandler instance.
Since data could be anything, you'd have to check what it is, or directly do it like this:
EquipShortcut equip = dataHandler.Get("key") as EquipShortcut
equip would be null if it isn't an instance of EquipShortcut.
Otherwise, use the helper class, e.g.:
List<EquipShortcut> equipment = SelectedDataHelper.GetEquipment(dataHandler.Get("key"));
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
That's all I needed.
Thanks as always GiL. Your timely help is eternally appreciated.
If I've just used the "Select Equipment" step, where is that SelectedDataHandler instance?
How do I hook into it?
It'd be probably the easiest solution to write a custom node that just forwards the selected data to whatever script you need it in :)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!