Hello everyone.
Sorry, kind of a long post because I am trying to be detailed and outline what I am looking to learn.
I have been able to use Visual Scripting to make on screen UI and Physical buttons, that interact with Events and Triggers within Script Machines. Using a ‘PlayerObject’ with a ‘PlayerScript’, all the basics like jumping via keyboard input, or opening a UI menu and changing volume with mouse clicks, etc. No issues.
I start having conceptual and understanding problems, when multiple objects and multiple scripts are involved.
I am now trying to combine a C# script with my existing Visual Scripting environment. A prior post here showed me how to generate the nodes I need, and I can bring up the C# script Public Void Function nodes in Visual scripting. But I keep getting these errors like: “Object Reference not set to an instance of an object” when I try to implement them into the flow.
Previously, in my own experience with just Visual Scripting alone, it was just about adding the Script Machine component to the Player game object. In this specific example, I am trying to learn the right way to use C# script nodes, assigned properly to the right objects, to do things in the VS environment - as well as proper object/script assignment and ‘This’ usage.
The current C# code spawns an inventory menu, which has an ‘X’ button to close the window. The X button, in C# code, triggers the Set Object Active to false (hiding the menu), but also triggers an update to translate which inventory items you clicked on - to then show up in a separate UI element (imagine cards you pick for a card game from one UI, and them then being in your hand which is another UI. The main pool of cards is the main inventory window - closing it, updates your own hand of cards on screen in another UI).
As it is today - it works 100% fine with just the mouse. The C# script loads, interacts, functions just fine when I use the moues to open and then click the X to close. It looks like everything flows and updates. So as learning, I am trying to test it out and make the keyboard fire an action to open/close the inventory through Visual Scripting and my existing Script Machine.
As a test, using this to take keyboard input to toggle the menu visibility. ActivationObject is on the ‘Inventory’ game object under the canvas. inventoryVisible is a bool to help track the toggle status. If it is visible, and thus is closed, the Script Machine should fire the ‘UpdatePanel’ Public Void Function from the C# script, to update the other UI element.
Which game objects should have the PlayerScript assigned (which is where this screenshot currently lives)? I have added the PlayerScript to the Inventory Object, the ‘close button’ object, several other objects. I have had the Inventory Visible bool be a scene and an object variable.
What do I replace ‘this’ with here, in the red box? If it isn’t the inventory object, the player object, etc. I don’t know what to input. In my brain, there is a player that moves around, and a UI. The UI can have a trigger, that would move the player object X distance or add hit points, etc. Can everything life on one object?
I can’t figure out how to ask the right questions to get help with this.
Does any of this make sense, and can anyone help point me in the right direction?
Thanks all.
Edit:
This is the full function snippet:
public class SelectedPowerUpsDisplayer : MonoBehaviour
{
public GameObject inventoryPanel;
public ItemList itemList;
[Header("Should be same Nr as displayed Child Slots!")]
public int maxActivatedPowerUps = 4;
List<Item> list;
public void Start()
{
list = itemList.list;
UpdatePanelSlotsForUsedItems();
}
/// <summary>
/// updates the slots with the selected items from the user
/// </summary>
public void UpdatePanelSlotsForUsedItems()
{
var index = 0;
foreach (Item item in list)
{
// do not take more items with you when there is no more space
if (index >= maxActivatedPowerUps)
{
return;
}
if (!item.IsActivated())
{
continue;
}
var obj = inventoryPanel.transform.GetChild(index);
obj.gameObject.SetActive(true);
var slot= obj.GetComponent<InventorySlotController>();
slot.item = item;
slot.UpdateSelectedInfo();
index++;
}
// update the rest of the free spots
for(var i = index; i < maxActivatedPowerUps; i++)
{
var obj = inventoryPanel.transform.GetChild(i);
obj.gameObject.SetActive(true);
var slot= obj.GetComponent<InventorySlotController>();
slot.item = null;
slot.UpdateSelectedInfo();
}
}
}
It has ‘Item’ and ‘list’ and ‘item.list’, which I think are all contributing the errors I have - How am I supposed to get these to be “visible” to the Visual Script nodes/flow?








