how to pass different variables on same widget

I have 1 widget that I use for 2 different purpose. 1 is used for passing weapon variables while the other one is used for passing armor variables. I believe the easiest way is to duplicate the widget and pass different variables from it but is there some way to do it with just 1 widget?
box

This is the function inside

If you need 2 widgets, you instantiate (duplicate) it. What variables you pass is up to you. The widget can decide what to use the vars for:

This would make 2 widgets, one of them is flagged as armor and gets 10, the weapon gets 5.


Other than that, you may need to clarify.

I think this is different from my case. Basically I have a mainmenu widget where I put other widget inside as sub widget of it. The one I circled are the same widget but I want to use it for different purpose. weaponslot_hud for searching item related to weapon while equipmentSlot_hud for searching item related to armor. This can be done by simply passing a type variable inside the widget but If I create a variable inside those widget, the value will be shared since they are basically 1 widget with different name. Hope this makes sense to you
image

So what exactly is stopping you from passing them variables?

the value will be shared since they are basically 1 widget with different name.

This is not true. They are instances of the same class. Each has their own variables. As in, they both have an int and a bool. But each variable can hold a different value.


Perhaps what you’re looking for is inheritance. A base class has some shared variables, and child classes can add their unique data on top. It works with widgets providing you do not alter their hierarchy.

Ok, I think I finally understand what you mean. Checking the instance editable made the variable show up on the widget details. This is exactly what I am looking for.
image

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.