How do i create variables in the constructor?

guys here’s what i wanna do:

i have an array of texts that’s set to instance editable.

each time that I create a new array element I want to also create other variables such as a float, an AnimMontage var, and a sound wave which must be a children of their parent text array.

could someone help please

1 Like

EDIT: My bad, I noticed too late that this was filed under Blueprint Scripting. Can you still make sense of it?

You can’t create new variables in a way you seem to be wanting to. If I understand correctly, the best thing you can do is change that array of texts to an array of structs that contain those variables. Something like this:

USTRUCT(BlueprintType)
struct FMyDialogueStruct // this sounds like it's for a dialogue system
{
    UPROPERTY(EditAnywhere)
    FText Text;

    UPROPERTY(EditAnywhere)
    UAnimMontage* Montage;

    ...    
};

Then, in your class you replace the text array with this:

UPROPERTY(EditAnywhere)
TArray<FMyDialogueStruct> DialogueLines;

When you add a new element to this array, you can set all the other variables along with the text.

1 Like

ah yes thats what i was looking for. i will try this

guys im actually encountering some other problems could u help me.
I’m using this function to get the typewriter effect.


and this is how I call the function I want to be able to print different stuff on each instance that contains this variable.

yet this is what it prints out wtf : D

can someone help me what other ways I can do this. my brain has stopped working after messing around with it for so long

Try making sure the widget and string variable are blank before the loop: Show Text → Reset() → Loop.

Also, just as thought experiment: If you interrupt the text reveal to switch to the next, won’t those delays be a problem?

the duration is the amount of time the text will appear before being overwritten. the delay was working fine before I added the struct, I guess the inner for loop is breaking stuff somehow

okay i removed the reset function that was a left over from my previous attempt which didn’t work out.

You could try creating a float variable “Time” that accumulate delta time:
if isPrinting → if Time > Duration, add next char to widget & Time = 0 → if Printed char.length == dialogue.length, break loop with isPrinting = false.

this way you can reset and retrigger without the problem of having a pending delay. Downside is you’ll need to tick, but you can set tick enabled when using the dialogue and disable when done. So no biggie.