Setting from Struct not (entirely) working

So this is a bit of an odd one I think, but bare with me here while I explain everything.

Basically I’ve set up an actor that has 10-12 Planes all set with partially transparent materials, all 0.01 units separated to create a sort of illusion of layers similar to art programs. This allows me to change the materials of each layer and the material colours of each layer to randomize things for when I spawn the actor. (They’re flat creatures with different markings, base colours, eye colours, etc). I am creating dynamic materials and adding them to variables in order to colour them and save them.

I have saved everything into a struct when someone clicks a button near a spawned actor, in order to call it later when spawning a saved/caught creature. (Don’t mind the cast to, I’m removing that I know it’s redundant)
This actor is where all the randomization happens. All of that is working (if you need visuals on those just ask me, but it’s too much to post in this initial post)

I then have a copy of the creature actor that only creates the dynamic materials for the markings, base colour, eyes, etc. and turns them into variables to use elsewhere.

So: I have Actor A with dynamic materials that randomize colour and then save those randomized colours into variables seen in the pic above, and I have Actor B that creates dynamic materials to then call later so I can set those materials in Actor B using Actor A’s saved information.

Now here’s the problem I have: All the marking colours work fine, but the primary, secondary and eyes are all randomizing colours when I spawn Actor B instead of taking from the struct that was saved.

Here’s what I have for loading the struct information (the spawn actor is spawning and getting information from Actor B) (I hope this image works it’s long…)

And here’s where I’m setting the dynamic materials for the markings (first image) and the primary/secondary/eyes (second image)

Please feel absolutely free to tell me if I’m doing anything dumb here, I’m still fairly new at things. Also if you need any extra info please let me know I have no idea if I gave enough.

Hey @AmaiTrick!

So before I deep dive into your stuff here let me just explain a nuance of structs that is not well explained or communicated if you’re not already in the know!

“MAKE” or “SET” doesn’t set the values… it sets the options. What you need to use is “Set Members”! “Set Members of Struct” is what most of us would consider using a “SET variable” Node!

Try using that to fix your issue and I bet that’ll do the job! For instance instead of adding “RHunDMStruct” as it’s created, create it THEN use “Set Members of Struct” to give your specific settings to the new struct before adding it to the array! :slight_smile:

Hope that helps!

1 Like

Thanks for the reply!!

Just to be certain, is this what you meant?

If so, it’s still unfortunately not working as intended :frowning:

Edit
Oopsie forgot to take out the redundant cast. Fixed that, ignore it again in the image.

Close! You’ll have to click the “Set Members in Struct” node and in the details expose the things you would like to set! It will only show the pins you tell it to! :slight_smile:

Omg I feel so dumb for not noticing that Ahahaha thank you.

Alright I have it set up like this (I’m still pretty new to structs hence not knowing the difference that you mentioned, I assume the ‘get’ node is what it wants here from the captured creatures struct):

Unfortunately still having the same issue as before.

Edit
Also tried connecting my CreatureData variable (struct variable with my struct data) into the Set Members ref and still same issue as before. Again, the marking colouring is working so it is pulling properly from the struct and saving to the struct, but something’s not working with the Primary, Secondary and Eye colours… I’m suspecting it has to do with the way I’m setting the dynamic materials but I’m not sure what’s wrong about them.

i think the issue is you’re adding a new copy (index++) but getting index 0.

with your current setup use GetaRef instead of GetaCopy and it should work (remove the ADD) or use SetArrayIndex(0) instead of ADD

Thanks for the reply!

I don’t see a SetArrayIndex node (Unless this is a variable type you’re referring to)
Sorry I am still fairly new to all this!

sorry its SetArrayElement.

the tricky thing with structs is knowing when you have a Copy or a Ref.

its worth looking into because if in the future you get you return your array/element by function (ie GetCapturedCreatures) you now have a copy again and it wont work.

for now you should be good though

So when I setarrayelement like in below image, everything totally breaks (unless I’m setting it up wrong?) and I get errors and I lose all information (markings, marking colours, etc that were all working fine beforehand).

Captured Creatures is a struct variable (connected to my specific struct) in my save game btw in case anyone was wondering. Creature Data is the same thing, but inside my player character)

Edit
I also changed GetaCopy to GetaRef, both seem to work the same way (no changes)
Given half my struct is working to set the final actor I don’t think it’s how I’m setting my struct. I think it’s something to do with the variables and such in my second actor. Picture of them is in my first post!

in your first pic you’re creating the savegame, which i assume means the array is empty, if so you need SizeToFit = true
it also means ADD should also be fine in this situation.

later in your code you’re Getting index 0 which is why i assumed you want to make sure you’re setting index 0.

so short version if you just want to add, add is ok but if you expect it at a certain index use SetArrayElement.

another potential issue is load order, if youre trying to load the save game before you’ve created/updated/saved the savegame it wont work

Gotcha. Right now I just want to worry about the first on the list (0) so that’s why I’m not doing anything with changing the index, but I also didn’t know that so that’s helpful thank you!

For load order, because you have to capture before you can summon the creature, the save is always happening first before loading (I’ll make this a bit more foolproof later on I just need to test the save/load), so load order should be fine.

Doing size to fit fixed the error issue! But unfortunately I am still having the randomized colours issue that I posted about in the first place ;^; I really don’t think the saving/loading from the struct is the issue as other elements of loading from the struct work just fine (markings, marking colours) which are all being kept in the same struct. So it’s working, just not saving the Primary, Secondary and Eyes correctly clearly.

ah sorry, i wasnt even looking at that part.

you cant save object references :frowning:

you’ll have to change that variable to a SoftObjectReference and use LoadAssetBlocking->CastToMaterial or whatever it is to restore it

Unless I’m misunderstanding, I don’t think I’m saving an object reference, I’m saving colour codes (in a vector) to then apply to a spawned actor later.

your markings are material or texture object references.

In short, those Blue variables cant be saved

Sorry, I am saving a material but it is working as intentended, as I said above. I’m saving a vector with colour codes:


The yellow (vector) colour code is what’s not working.
The blue variables (the markings) in the pictures in my post are working fine, they are saving, but are not the issue I’m having. :frowning:

are you sure its working? its hard for me to read the small code in pics

but if the material is invalid, then you will fail to set the vector parameter on the material since it doesnt exist.

Yep it’s definitely working. All the materials are saving! I can get the marking designs (materials) and the marking colours (colour codes) to all save and load (I know this because I have 8 markings that randomize, so if they consistently show up the same between wild and caught versions then they’re definitely working).

But the Primary colour, secondary colour and eye colour (all vector codes) are not loading correctly (or not saving correctly, not sure which)

Edit
Here’s how I’m setting Primary/Secondary/Eyes to then reference later (NOT working):

And here’s the Markings(Working):

try setting your alpha to 1 (ValueA) on your SetVectorParameter

also you can actually save LinearColors instead of vectors

I did not see it was set to 0, I must have accidentally set it before. Either way, set it to 1 and it still randomizes colours instead of setting the saved colour :frowning:

I didn’t know you could save colours like that! Thanks :smiley:

Still having the same issue… can’t figure out why still. Thanks all for helping still!

Edit
Actually that does give me a clue. Alpha controls opacity right? So logically if it was correctly saving and loading primary (which was set to 0 Alpha) then the loaded colours should have been invisible for Primary specifically. But they weren’t which means it’s not loading the saved colours. Hmm…

Actually nvm, I’m only saving the 3 colours now that I look at it. Alpha wasn’t being saved in my vector. So that shouldn’t have affected anything.