Creating unique actors and data tables

Hi, I’m working on a card game and could use some help.

I’m creating my cards using widgets getting, title, art, description etc. from a data table.

270366-card.png

270368-drag-and-drop.gif

I have 3 copies of the widget displayed and a drag and drop operation so the player can choose the card he/she wants. Right now I’m kinda cheating by hiding and displaying a copy of the widget and have it displayed on Drop detected.

Here the question

  1. Is there a way i can create 3 different cards from the same widget? i know i can create 3 different widgets and randomly assign them Rows from the data table. but i think it would be better/cleaner if i could do it all from the same widget.
  2. I also need a way to pass the information along when i drop the card off in the player hand. but i guess if i get help with the above this will get figured out.

Is there a way i can create 3
different cards from the same widget?

Do you mean to duplicate an existing widget? I think you mean something else.

if i could do it all from the same
widget.

Do what exactly?

I don’t see a problem here. Although it depends on what makes it different. If it’s 2 different potions and they heal for different amount - that’s just a matter of setting a variable. That’s easy. Giving them completely different functionality is a different story altogether.

I’m also wondering if I can pass along
information from my data table when I
drag and drop the card to the player
hand

Yes, create a new widget and feed it data from the DT.


So are you using a separate widget for each card? The more I think about how you refer to it, the more I think it’s true. And that’s not the right way to do it. Having 50 cards is probably manageable, but makes it impossible to grow efficiently.

You should at least consider splitting them into categories:

  • healing cards
  • damaging cards
  • special cards

But this might not be enough for something that’s a tad more than basic.


Consider the following.

  • each card is an object, not just a plain widget
  • all cards inherit from base class
  • base class handles all the common functionality (casting cost | card name | card type | holds onto the details regarding the card’s look | rarity | card in hand / playfield behaviour and so on)

That’s a base card. It does not do much on its own. And this is where inheritance and actor components come in handy.

You create a bunch of actor components:

  • damaging component
  • healing component
  • a component that can draw cards
  • a component that can discard opponent’s cards; and so on…

Whenever you want to design a new card, you create a child of the base class (so it can already do and behave like the parent) and start adding components you prepared - at this point it’s a matter of drag & dropping as many as you need.

Only at the very end I’d worry about widgets - they should be visual clues only. The base class can create a widget and customise it based on the class defaults and/or any actor components that the children added.

i’m wondering if I can create 3
different versions of the potion card
out of 1 widget.

For experimenting with something simple, create a custom event inside the widget that can read and set information regarding its own elements from via a data table query.

This way you have 1 widget and create 3 (as many as you like) instances all with different statistics. The downside is that you can’t possibly encapsulate all the necessary functionality needed by all cards in a single blueprint. (you can, sure, but it’s gonna bite ya sooner rather than later)

If you consider growing this beyond simple, you need modularity.

Actor = object. At least in UE4’s blueprints.

Also, this should be fine for something smaller. You might be able to pull it off if you split your cards into categories. There’s going to be a lot of repetition in the code, though :expressionless:

What i have been doing is this:

  • I have 1 widget for the potions.
  • When i enter the “play phase” of my game I run a function that selects a random row from my data table and casts it to the Widget.
  • I then had the cards run through another function who handled the variables. This gets messy quick.

Trying your method. Is the base class an actor or an object?

Am i doing this right?
this is my Base card widget.

and this is an actor component, i’m using functions to set the base functionality.

Using functions for this is going to be tedious. It’s OK in the base class, but for children you will be better off with [actor components][1] ← great intro material here.

They are reusable - chunks of functionality that you can add / remove on the go.

Imagine your opponent casting a
damaging card at your face to which
you respond with a counter effect that
replaces the damaging component with
a healing component. When the
card connects, the whatever existing components
of the card activate, delivering a
result.

So rather than having a data table that lists everything that a card can have, it would list which components the card has, and how strong they are. The entire healing logic - the payload of the card - would be contained within that component. It would also hold text, images, sounds, special fx and more.

To visualise it, a widget would read a list of components a card has and set up its own text fields accordingly.


Also, you can expose variables to the constructor:

So you can do this (the DoMoreStuff could spawn any components the card may need) :

And, eventually, automagically spawn cards like so (top - base / bottom child):

It’s going to take a while to get any of this going so just keep tinkering!

ok, am i going about this the right way?
I created some variables in the base card i can edit in the child actor “Potion of Midas”

How should I fire of the Setup event? its in the event graph of my base card.

You can do it in the constructor like in the very first image I attached. The event fires when you create a card, pulling data out of the data table.

Ok, got it working! How can i get my newly set variables, such as card name to the widget controlling the text displayed on the card?

The event pulls a struct from a data table, so your object has access to the struct. Have a look at the the 2nd image I posted. It creates the widget in the sequence.

You can have an event in the widget similar to the one in your object and call it after widget creation; but there’s an even better way:

Create a struct variable in the widget itself and Expose it on Spawn - the Create Widget node (refresh it by right clicking) will now show a new pin for the struct. Plug the struct there. Essentially:

Card object pulls data from a data table and feeds it to the widget via an exposed struct variable.


Alternatively, instead of feeding widget just the struct, you can feed the entire card object to the widget so it has full access in case you ever need it.


This method of the object spawning a widget also opens up for very efficient communication via Dispatchers later on. Quite handy once things get complex.

ok, is this what you meant?
I’m creating the widget from the event graph, feeding the struct and using the struct to set the title of the card in the widget.

Looks fine, does it work the way you need?

I would like to try and feed the entire card object. how do i set this up?

The same as you’re doing it now, but instead of a struct you can plug in your actor into the widget’s exposed pin. This way the widget can then get actor and get its struct.

This is how i setup the communication in the construct script. I don’t quiet understand how to feed the actor to the widget. I would like all the variables in the actor to be visible to the widget.

In order to feed the struct to the widget, you created a variable of struct type and exposed it, right? You called it The Card Struct. It now shows on the Create Widget node. As seen in the pic you attached before.

Do the same for the actor - in the widget create a new variable (let’s call it The Card Object) - make sure its type is the same as your card actor type, and then expose it and make it editable.

You can now plug in the entire actor into the widget Create node so the widget no longer needs its own struct; it can instead pull data directly from the actor’s struct.

What’s more, you can actually bind widget’s fields to that actor’s struct:

271662-untitled.png

So I got the actor to communicate with the widget as you described and I did bind the widget fields to the actors struct. and got this:

271649-2.png

So its sending the variables to the widget.

The problem is this. I can’t see the variables on the actor child anymore. Am i setting this up correctly?

The problem is this. I can’t see the
variables on the actor child anymore.
Am i setting this up correctly?

Adding it here as it was getting tight up there.


A little confused regarding what you’re trying to achieve now. Can you explain?

I can’t see the variables on the actor
child anymore.

The base actor class pulls data from a DT and holds onto the struct. It then pushes the data to the widget, right? You’re sending self reference to the widget I assume?

So you started creating child actors?

Maybe you never store the struct data you pull from the DT? I can’t see it in any of the pics. Also if you’re doing stuff in the Construction Script, a child will need to manually call its parent’s Construction Script (in the child right click the Construction Script node and Add Call To Parent Function).