Forum rules - please read before posting.

Running selected inventory interaction from script

I am working in a game that has an interface that could be described as interactive fiction but instead of typing you click on words, for which I have a custom interaction system, the idea is to create full sentences in order to trigger interactions. I have no problem with that, and the interface is working just as I expect it. But I am also trying to keep traditional point and click functionality in some cases (picking up objects, combining, using, giving, etc.). I have also achieved most of this with custom scripts and events, so I can do simple use interactions on hotspots and inventory. But I ran into a problem only when trying to use or give an inventory item to a character. I need to create a way to trigger that interaction, I am trying to hook onto the OnHotspotInteract event.
I read in the manual that I can use the hotspot's RunInventoryInteraction method. I figured I could just pass null as a parameter in order for it to run currently selected inventory item. Something like this:

KickStarter.playerInteraction.GetActiveHotspot().RunInventoryInteraction(null);

But then Unity crashes right away. Everything freezes. No messages, nothing. I have to close it from task manager and reopen it. Tried with -1 instead of null, and it also crashed.

Then I thought of trying something like this:

hotspot.RunInventoryInteraction(KickStarter.runtimeInventory.SelectedItem.id)

It crashed too.

So, in a nutshell, what would be a good way to trigger the selected hotspot's inventory interaction via script?

Thanks in advance!

Comments

  • Also, I'm using the last version 1.71.4
  • I wonder if this is caused by there being two functions similarly named but with different optional parameters.

    Try opening Hotspot.cs, and replace:

    public void RunInventoryInteraction (int invID = -1)
    

    with:

    public void RunInventoryInteraction2 (int invID = -1)
    

    That should then remove any ambiguity. Does the "null" call you made above then work?

  • Hi Chris, I couldn't get it to work. It crashed Unity as well. But I fixed it (I think), so I'm writing down what I did for posterity :# :
    -I use interaction method: Choose hotspot then interaction
    -My interaction menu is empty, but it's there so that I can hook onto the OnMenuTurnOn event (I resorted to this since, as far as I know, there is no native "on hotspot click" event).
    -So when my empty interaction menu is turned on, it turns on my special interaction menu, which triggers interactions via forming sentences with a customized script.
    -With "choose hotspot then interaction", once I have an item selected, I click on the NPC in order to give the item, but it doesn't do anything (that's why I tried to hook RunInventoryInteraction onto the OnHotspotInteract event, which crashed Unity, so I'm avoiding that). And then I realized that if I change the inventory interaction from type "give" to "use", voilá! it works! It's good for me because I am not using a full hotspot label and there is no difference between use and give in my game, but I don't see a reason why "give" doesn't work while "use" does.

  • With "choose hotspot then interaction", once I have an item selected, I click on the NPC in order to give the item, but it doesn't do anything

    It should do, provided you have Include Inventory items in Hotspot Interaction menus? unchecked in the Settings Manager.

  • Great! Now it works with a give interaction. Thank you.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.