Forum rules - please read before posting.

Referencing the hotspot that opened a generic menu

I would ask for some help , If I may - because I am completely stuck...

My Hotspots open a generic "custom" (Unity UI Prefab) menu from a 'Look at'  interaction. (much like the Inventory demo) The menu contains possible user selections that are handled by a custom action when the choice is submitted.

Because both the menu and the "submit" action are generic I cannot define the hotspot to turn off in either action list.. My Question is.. how do I get/pass a reference to the clicked hotspot so that I can turn it off once it has achived my "used" status...

I have tried setting a global variable ("current_active_hotspot") in the look interaction-  but am having problems targeting the hotspot when I grab it again , I have tried the Canvas EventSystem - but Hotspot selection actions are not registered by AC

I would guess the answer is staring me in the face - but being a total newbie.... I would humbly accept superior knowledge

Thanks in advance if you can help...

Comments

  • Welcome to the community, @Simonr.

    From your description, I would imagine you could make use of parameters to do this.  Parameters are a way for you to change the content of Actions each time they're run, and you can use a GameObject parameter within the Hotspot: Enable or disable Action to change the affected Hotspot dynamically.

    You can find a tutorial on their usage here.  While parameters are usually set at the time their containing ActionList is run (using ActionList: Run), you can set the values of individual parameters at any time by using the ActionList: Set parameter Action.
  • Thank you Chris
    I will read the tutorial and see what I can figure out. My guess is that this is quite a common scenario , so I will document a case solution / use example (when found) for the new wiki page(s) - trying to find an answer by extrapolating problem cases & questions was getting me nowhere:  being a newbie I dont have the indepth knowledge to point myself in the right direction.
    Thank you very much for your assistance.
  • edited August 2016
    Ummm... the biggest problem here is not how to do it, but how to do it in a clean and efficient manner. A lot of stuff, even very complicated stuff can usually be done with actionlists assets and parameters, but it may often leave you with a ton of action lists assets or very hard to read actionlists. So, if all you want to do is disable a hotspot, when you are done with the player's actions, or change the hotspot's visibility, then a custom action might be a much easier and efficient solution, especially if combined with the gVar reference you were already using. You could for example use some of the "find" methods in unity to find the object by name or you could pass the name of a script attached to the hotspot to get to the object and disable it (even if that script wasn't even doing anything). Once found, you could even disable the object using AC's own methods.

    It'd probably be worth it to take a look at the AC custom action's tutorial here. You can also take a look at the wikia were I've placed a basic Custom action's walk-through.
  • I have looked at the "params" approach - and I cannot see how I can get them to be presistant between action lists other then using the global vars -(yet)... So far I have been persuing the gVar method (set on the look interaction) + custom actions (including"find" ) - but that means (AFAIK) that I have to set the gVar manualy for every hotspot (not ideal : I have a LOT) - I did a (very bad) diagram of the flow to make it clearer : (This all sounds similar to Alverik 's comments - :: Thanks ::) I would be using AC's methods to disable the HS... and will probably go with the custom action  { I am getting quite used to writing them now :-) } However : my approach strikes me as a bit 'Heath Robinson" using a sledgehammer to open a peanut ...  when so much is efficiently done by AC nativly... (Please excuse spelling - Typing to a deadline ;-))
    image

  • Chris : As an aside - Is there a particular reason why the selected hotspot does not register in the Event System  (** It may be my buggy code that means it does not show) : In this instance - I could use it to dynamicaly populate the Global var on the first interaction... (which would be very usefull :-) ) - I have a couple of ideas why it might not be happening - but I would rather hear it from the horses mouth before  spouting and looking like a plonker !
  • edited August 2016
    Got It :

    OK - After the last action ( following the "Menu Off" call : in the case of an acceptable user input) you can use a custom action thus :


    override public float Run(){           
            Hotspot myHotspot = AC.KickStarter.playerInteraction.GetLastOrActiveHotspot();
            // validate : dont want to have a bad object ref ....
            if (myHotspot != null) {              
                 myHotspot.TurnOff (true);
                } else {
                 Debug.Log ("Oh Duckpants - I must have made a Boo Boo ! Lost the Hotspot");
                }
                return 0f;
    }

    And : Discoveries -
    (1) AC. namespace has to be defined for the reference in Run() scope - can anybody confirm ?
    (2) Using this method does not require a global var to be set - you don't even have to know the target of course :-)
    (3) GetActiveHotspot() does not work (returns Null as soon as the  first click is made / first opertunity to test comes about) - at least in my project that is what happens
    4) this works with other menus being opened and closed during the process

    I think this is possibly the cleanest way ?

    + Thank you Chris for the thouroughness of a method like GetLastOrActiveHotspot() :-) & please ignore my eventSystem question : this does the same job.
  • Brilliantly solved! I must be honest and say I'm still getting used to AC's API too, so I didn't think of that. About (1), that's strange, don't all actions have the namespace defined at the top (using AC;), can you check if you have that in your script?

    Anyway, I think this would be a great addition to the wikia! :D If you have the time would you mind adding a page with your code and a simple explanation of what it does? (just hit the contribute button and select add a page). Also leave your username somewhere in the body of the page (if you want) ;) .

    Cheers!
  • I will as promised :-)
  • +1 for the first use of "plonker" on the forum!

    Nice solution.  It's true that GetActiveHotspot is null at the time of an interaction - the Hotspot itself is de-selected before anything else.

    For completeness, OnHotspotInteract is the event that runs when an Interaction is run, not OnHotspotSelect - that's just when it's highlighted.
  • ChrisIceBox : 'simonr' could be Simon "Rodney" ;-)  - & If the accent I detected on your tutorials is British - then you will know what I mean ... :- and thank you for "OnHotspotInteract" completeness - will keep that in mind : usefull interaction point.. Now off to search to see if there is a way to turn a GameObject mesh into a hotspot directly :-)
  • Add a trigger Collider and a Hotspot component.  I've now got a chandelier to take down..
  • ChrisIceBox :Smashing .... er..
    Re: Hotspot to Mesh - I had misunderstood your 1.4.3(?) release comment about "now being able to wrap hotspots" - I presumed it meant wrap to 'shape' [ ? automaticaly cloning GameObjects mesh colider as the hotspots colider (and say increasing by 0.1 scale)... (which is what you can do, as you designed..) ] : but it is too labour intensive to do manualy with my quantity of Hotspots - so we are back to cubes for now - ATM . I am just grateful to be able to use the present wrap and not have to move from 0,0,0..... !
    BTW - Very glad I found I can use a single instance of a "look-at" interaction as a generic action - nice little touch to speed things up :-)
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.