Greetings! Sorry to bother you with my problem once again! In order to do certain tasks that could not be handled by ORK directly, I have coded a couple of functions to complement those provided by the plugin itself. One thing that have been giving me a headache, though, is how to instantiate and refer the newly created HUD to a certain combatant via code. Basically, I want to create a new instance of a HUD inside a game object (another HUD), and link this new HUD to a specific combatant so it can get data provided to it (such as combatant name, max and remaining HP, the usual stuff). Is it even possible to instantiate a HUD via code like this? Thank you for your time and consideration!
  • Untested, but should generally be doable.

    E.g. try using a HUD Combatant Object (Content Provider) component on your HUD prefab and set the combatant's game object as it's user after spawning the prefab.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited June 2023
    I write my question here, because the topic and title is the same:

    Ive searched in the source code where the HUDs are created and its content set because I trying to find a way to instantiate a HUD and bind an equipment (or item) to it via code.

    Edit - btw, why the schematic node Call HUD often do nothing? What requirements must be met for a HUD to be displayed via Call HUD?
    Post edited by Tzunamii on
  • Tzunamii said: Ive searched in the source code where the HUDs are created and its content set because I trying to find a way to instantiate a HUD and bind an equipment (or item) to it via code.
    Haven't tested it like that, but I'd suggest using an Information type HUD for this.
    You can get/create an instance via:
    HUDInstance instance = Maki.UI.GetHUD(hudAsset);
    hudAsset is a HUDAsset class (i.e. the actual asset of the HUD).
    Needs the GamingIsLove.Makinom.UI namespace.

    With that, you can set the user of the HUD:
    instance.ChangeUsers(user, ListChangeType.Set);
    Tzunamii said: btw, why the schematic node Call HUD often do nothing? What requirements must be met for a HUD to be displayed via Call HUD?
    Beside the display conditions of the HUD, some HUDs are also bound to specific states, e.g. the Turn Order HUD can only be displayed during turn based battles, or the Tooltip HUD only when a tooltip is available, etc.
    The main use of the Call HUD node is for Information HUDs
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thank you! This works perfectly. Didnt know that you can use anything as user xD. So the equipment can act as an user and the HUD can fill that information. Nice.

    Is it possible to instantiate an instance under a parent (or change it, after creation)? Or to put it another way: How can I get the *GameObject* or *Rect Transform* from that?
    gamingislove said: The main use of the Call HUD node is for Information HUDs
    Ah okay, thank you. I wasnt sure which type of HUDs to use in general. (Except for the obvious ones of course :))
  • The HUD user is just the content that's available to the HUD components on your prefab. Via some content provider components, you can even use them outside of HUDs at any time :)
    Tzunamii said: Is it possible to instantiate an instance under a parent (or change it, after creation)? Or to put it another way: How can I get the *GameObject* or *Rect Transform* from that?
    I don't think that's currently possible. I'll look into adding functions to get the IHUD instances from the HUDInstance - this is the actual HUD (via an interface) that displays the stuff. E.g. for the Unity UI module, this is the HUD component of your prefab.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.