Forum rules - please read before posting.

Setting "Object with Script" Parameter for "Custom Script" Hotspots at Runtime

Hey Adventure Creator community,

I hope you're all doing well! I have a question regarding the usage of the "Custom Script" hotspots in Adventure Creator. Specifically, I'm wondering if there's a way to set the "Object with Script" parameter at runtime for these hotspots.

Here's a bit more context: I have a prefab that contains a hotspot with a "Custom Script" interaction source. I'm instantiating this prefab during runtime to dynamically create hotspots in my game. However, since the prefab is instantiated at runtime, I need a way to set the "Object with Script" parameter dynamically as well.

I've explored the Adventure Creator documentation and forums, but I couldn't find a direct solution to this issue. I'm wondering if anyone has encountered a similar situation or has any insights on how to achieve this dynamic assignment of the "Object with Script" parameter for "Custom Script" hotspots.

Any guidance, suggestions, or workarounds would be greatly appreciated. I'm open to exploring different approaches if there's a way to achieve this functionality. Thank you in advance for your help!

Comments

  • The field you're looking for is customScriptObject, which is a property of AC's Button class.

    Being a part of Button means that this is a per-Interaction property, rather than a per-Hotspot one. To affect it, you'd have to access the Button you wish to modify.

    AC has different functions to get a Button depending on the interaction type - GetUseButton for example, will get the first-found Use interaction with a given Icon ID.

    Alternatively, if you wish to update all Use interactions with the same value, you can iterate through its useButtons List:

    Hotspot myHotspot;
    foreach (Button button in myHotspot.useButtons)
    {
        button.customScriptObject = myNewObject;
    }
    
  • Thanks @ChrisIceBox for your detailed response. I will try accessing the customScriptObject through the Button class as you suggested. Your explanation has been very helpful in guiding me through the process.

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.