Download

Add Widget Component at Runtime

Hello everyone!

For my game project I want to implement some TCG-Elements. I designed a Widget Blueprint as a “Card” and now want to add multiple instances at runtime to an actor (->into 3D space). When I manually add a Widget Component for the actor, everything works just fine,
but when I add them at runtime with “Add Widget Component”, nothing happens. Do I have to call some extra functions?

Futhermore, the construction script of this blueprint doesn’t get called?!?!

Okay, I got it. But somehow the different cards are stacked on top depending on the distance to the viewer. I have 4 cards sligthly on top of each other, like in HEX or Hearthstone, but when I shift to the left, the lower cards get displayed on top of the physically overlaying cards, resulting in very strange looking images… How can I disable that?

So you solved the construction problem of spawning a specific widget component, but you didn’t think to share how you did it and immediately went on to the next problem.

That’s… Really bad etiquette. I myself have this problem right now and I don’t want to spawn a new actor for every single one because that’s incredibly wasteful and I got excited thinking I’d found my answer and instead I’m met with this.

For the record, what you’re experiencing is z-fighting. Look into the damn render settings and change the CustomDepth/Stencil value stuff to overcome these problems.

To create a widget component runtime using Blueprints:

  1. Call “Add Widget Component”
  2. Call “Create Widget” with the class you want to create
  3. Call “Set Widget” with the Widget Component returned by “Add Widget Component” as Target and the created Widget as the Widget.

Like this:


You can then Set Widget Space, Draw Space etc. as needed on the Widget Component.

I had to do this myself today and saw this thread. I hope this helps.

Cheers!

I tried this approach in Construction Script using the Construct Objec from Class.
It works both in the Editor and Stand Alone Game Preview.
However in Play and Play in New Editor Window the widget just disappears…
Maybe Im wrong but Construction Script is called before Event Begin Play.
So why the widget disappears?
Again, it works fine in Stand Alone Game.
Anyone got that too?

I would like to do that way cause I have more control creating dynamic widgets.
AND using create object from class I dont need to reference the player.