Set Static Mesh from Data Table is invisible in Game - but its name is Printed (found/set)

Can you please help? With the help of @L1z4rD89 I made a Widget that picks 5 random words to make a full Name of a weapon. Now I want to use that a word in the Name, e.g. “Slicey” or “Hammer” to drive which Static Mesh the weapon gets.

But Set Static Mesh node, with the Static Mesh component connected as Target, and a Static Mesh variable connected as the new Static Mesh = Static Mesh turns invisible in game.

I used a Data Table with a Weapon Name (String), and exact Mesh Name (of a Static Mesh in UE).

I have code in my Widget, that randomly chooses a row from my Weapon Data table = to pick it’s Name (String), and Static Mesh (goal).


.
.

On BeginPlay, my Sword Actor BP is already in the Level, and its existence triggers the random code which is already working to set the Name display on my Widget > which (the Widget) is a component in Sword Actor BP.

So this Sword Actor BP has this Widget and a temporary sword Static Mesh “component.” In that BP, I cast to the Widget, to get the value of its Random row number, which decides the Static Mesh Name, which I want to replace as the current “Static Mesh component.”


The problems:

  1. When I load the game, Event Begin Play fires: The Widget code works to give the Sword BP its name; but every Sword Actor BP has an invisible Static mesh (some are already placed in the level, some are spawned from a touching a trigger > also invisible. But the random Weapon name shows – so I know the Widget-to-BP communication is working).

  2. I know that they are being assigned the “Static mesh” name, because I print the name of the Static mesh (which got pulled from the random Widget selection code).

  3. But the mesh is invisible??

  4. Problem 2: Technically the Sword Actor BP uses “Static Mesh component” not “Static Mesh.” But the Set Static Mesh node expects an input of “Static Mesh.”

  5. And In my Struck (that uses the Data Table), I cant set the Static Mesh variable to “Static Mesh Component,” or else the Static Mesh name in the Data Table (loaded from CSV file), disappears on its own.

  6. [I did try to change my Struct variable to “Static Mesh Component,” then change the variable in the Widget to “Static Mesh Component” > which sends to the Sword Actor BP. But the mesh was still invisible (or did not send because the Data Table erases the Static Mesh name when I choose “Static Mesh Component.”]

  7. So what is the problem???

  8. Also I cant put the random-selection code in the Sword Actor BP (or dont know how), because I need to access Variables in the Widget BP [UMG code] (which seems harder to go to, vs Widget > to BP code).

  9. But ultimately I want a full Data Struct that changes 5 variables of the Weapon BP (e.g. emitters, color, mesh). While I only need to change 2 text labels in the Widget UMG.

  10. I also tried to communicate between them with BPI (Blueprint Interface). But it failed to send Widget info to Sword Actor BP.

Place a PrintString behind CastFailed and see if it gets printed.

1 Like

Thank you. I tried and it printed nothing.
Then I tried adding another Integer *Column, with a Row Label in my DT (that was selected at the same time as a Word that was printing). Then in the Widget code > I set this Int as a new Variable Int > which I pass to the Sword BP (so the Int is saved in the Widget > so I can Cast to-extract it).

But this Integer Variable printed as 0 for five objects (when it should be a # 1 - 10).

So I knew that the Sword BP was not getting the correct values from the Widget BP. Or maybe both code is running at the same time, and the Sword code is running before the Widget code finished executing to set the Integer Variable.

So I fixed it by adding a 0.2 Delay after the Set Text node in my Sword BP (which was already working). But now a 0.2 Delay, then read Static Mesh Variable (from Widget BP), and set it in Sword BP. And this works!

  1. Anyone have a better solution? Im not familiar with Delegates etc.
  2. Is there any chance (with lag, or level reloads) that my 0.2 Delay will fail to always execute my Widget code first, then Sword code last?

You could transfer the name generator function to the actor itself and use a TextRender for displaying the name. Or create one separate actor who creates the names and then assigns the names to the weapons. Are you using the WidgetComponent to show the name?

1 Like

Yes. The Widget Component has 2 text boxes, also using special Scrolling Widget text box code (C++).
I tried before, communicating between the Widget and Sword with a BPI, but it failed to pass Variables. So I figured Widget/UMD is finicky? thus easier to put the random code in the Widget?

Idk the correct way to use a Manager Actor to send variables to UMG Widget. But im also concerned if [I use another actor as a Manager], and the Player saves their game - how to save those random Vars, and recreate them as the same weapon? I’d need to save the Manager and the Weapon, and the Widget.

Or is it possible to write to Data Tables live in UE - as a save storage vessel for the random Vars?

Well, you could do it like this:
Create the name generator in your GameInstance
Actor BeginPlay => Call to GameInstance
GameInstance sends name + mesh to Actor
Actor sets mesh and puts the name into the widget

You could then save all names and your actor specific details in a SaveGame

1 Like