Hey everybody,
Hey @ChrisIceBox,
let's say my Player is surrounded by multiple hotspots and they are all collected by my script using the DetectHotspots component set to Custom Script. In the settings, cycling through multiple hotspots is enabled. Cycling through them with my gamepad works.
Now I would like to have control over the hotspot that gets selected. It should behave like this:
How can I specifically activate a hotspot without messing up the cycling index? Is it possible to set the index to a specific hotspot? Or should I handle a scenario like this in a different way?
Thank you and happy holidays!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I'm not clear on your meaning. If the three Hotspots remain within the Hotspot Detector component, then the selected Hotspot should remain unchanged if you've enabled "Cycle Multiple" as the Player moves towards different ones.
There is a GetSelected function you can use to extract which Hotspot is the one selected with the input cycle, but the updating of this is handled internally. I can see about adding a function to set this publicly, however.
Let me rephrase the question:
If I add multiple hotspots to the DetectHotspot component with AddHotspot, how can I control via script which one is the highlighted/selected one that the player can interact with by pressing the InteractionA button? Without messing up the cycling index?
I want the player to be able to cycle between multiple hotspots, but if they move up closer to a hotspot, it should select/activate that one. It seems like if I try to do this, it jumps back to the hotspot selected by the cycling index.
Thanks for clarifying.
The function I mentioned above that would let you set the selected Hotspot should allow for this. I will look to include it in the upcoming v1.82.2 release.
PS - i spent so long typing that Chris replied in the meantime, maybe I shouldn't try to help lol
Thank you so much Chris
Thank you BecauseBecause, much appreciated! That is a very valid point and I hope it will be enough that the player can cycle through nearby hotspots and also has a button to highlight all hotspots. Those things are already covered by AC's functionality, but I would like to have more control over the hotspot that is activated based on custom conditions (like, choose the closest hotspot when the player is moving) and adjust the cycling index so that it cycles from the index of that hotspot. I hope that makes sense. Thanks for your input!
The new SetSelected method of the HotspotDetector component instantly solved my problem, thank you @ChrisIceBox!
Next I tried tackling the recognition of InteractiveBoundary so it also works for my hotspot detection. It basically works, but it seems like there is some problem with checking if the Player is present in the volume, it looks like the Player is not inside but the hotspot is still being collected, I will do some more tests to figure it out.
I found an issue with the InteractiveBoundary component btw, I'm pretty sure playersPresent should be a HashSet, since the Player gameObject is being added inside the Update method for Transform detection and the count goes up. Changing the adding and removing logic would be another option I suppose, but just changing the list to a hashset would probably solve the issue
I think the problem with the playersPresent list in InteractiveBoundary is the cause for my issue, I think it's working now.
A HashSet still needs its contents checked before an addition/removal attempt is made, but you're right about it increasing the count.
Replace the Update function with this:
I suppose it would be better to check the contents, but I don't think it is necessary for a HashSet? Anyway, just checking if the list contains the Player GameObject is probably the cleaner solution xD Thanks so much for the quick response Chris!
@ChrisIceBox is it possible to have collected hotspots in the detector, but none of them are selected? I would like to set the closest hotspot as selected/active, but if no hotspot is close enough to the player, none should be selected, but the user should still be able to cycle through them. Is this already possible or would it need a Deselect method or unselect by using SetSelected(null), which is currently not doing anything.
When a detector is in use, any Hotspot within it is considered potentially "close enough" - by default. Are you looking to further limit selection to a given distance within the detector?
If you set your Hotspot detection method to Custom Script, a Hotspot Detector will still track nearby Hotspots, but their selection is left to scripting. The NearestHotspot property can be read to get the nearest Hotspot.
At the moment my custom script detects all Hotspots on screen and selects the closest one to the Player, so one hotspot is always selected.
If the player is too far from any hotspot (defined by some max distance value) I would like to have none selected until the user cycles through them.
The DeselectHotspot method should manage that, so long as you're similarly using PlayerInteraction to select Hotspots.
Sorry, but I'm confused.
I'm using DetectHotspots.SetSelected() to select hotspots and when I use DeselectHotspot() it seems that the hotspot gets selected again right after, the label doesn't disappear, but I can see the highlight flashing. Is that because the hotspot detector still tracks nearby Hotspots?
It's weird, because after calling DeselectHotspots(), if I log Kickstarter.playerInteraction.GetActiveHotspot(), I get null, but on screen the label is visible and the highlight is on.
When Hotspot detection is set to Player Vicinity, then AC will automatically select a Hotspot within the Hotspot Detector. It's not possible to have no Hotspots be selected - but it is possible, through the SetSelected function - to dictate which does get selected.
If you instead set Hotspot detection to Custom Script, then AC will not select Hotspots automatically, and it is down to your custom script to call PlayerInteraction's SetActiveHotspot function. You can still rely on the detector to keep track of nearby Hotspots, but you'll need to manually read from it to pass a Hotspot onto PlayerInteraction.