#How does one smartly handle and call upon these variables?

1 messages · Page 1 of 1 (latest)

teal junco
#

Hello everyone! I created a thread as to not interrupt Santo and AO.

I have this recycler that will break down various units of scrap. The scrap will have multiple different models.

However, here's the question: How do I get the scrap to contain two numbers, each "model" will have different values, but the same name. How does one make the recycler (a different blueprint entirely) check if those variables exist and then use them?

#

I thought there was a rather simple way of handling this data, but googling or even resorting to ChatGPT (gasp) seems to be futile. Probably because I'm not sure how to word the question.

fluid pecan
#

Easiest way would be to make use of best friend inheritance.

Scrap will be a blueprint, with a base class that contains the scrap mesh and this "number".

Recycler has a reference to all the scrap coming in, so can simply cast a scrap to it's base class to see it's value.

teal junco
#

By base class do you mean "object class"? Or is there a different class you're refering to?

fluid pecan
#

by a base class I mean a class that each type of scrap inherits from. Like when you're making a character you inherit from the Character class

teal junco
#

Gotcha, and so if my scrap is a actor there's an "actor class" I can use? I'm sorry if I'm not following exactly. I'm not super familiar with this area.

#

Oh, are you talking perhaps about child blueprints which would make the "scrap" blueprint a class?

fluid pecan
#

No, it seems there's some fundamentals you're missing here on OOP and the Editor, fundamentals that make it quite hard to explain what I mean.
I'd personally advise going through some of the beginner resources of the pins of #ue5-general and #blueprint .

Essentially what you want is a scrap blueprint as a base with no assets that contains the variables needed, and subclass that in order to get your actual different types of scrap

teal junco
#

Maybe, I'm thinking it may just be a terminology thing. You said no to the child blueprint question but when I look up subclass tutorials they get into child blueprints?

fluid pecan
#

I said no to it all, because you've essentially said the same thing twice. It's definitely a terminology thing, but not knowing the terminology makes it very hard to explain what to do.

#

you're making a blueprint that is a child of a given class. It doesn't make a scrap blueprint a class, it already is one, it also is already an actor class.

teal junco
#

Ah, I see.

#

Yeah I think I understand now.

Essentially
item (stores the data)
├── scrap
└── computer (another form of scrap)

Then cast to Item -> get variables

#

That way I won't have to cast to scrap or computer seperately

fluid pecan
#

kind of, what's the computer in this sense?

#

ah, no, it's more like

#

item (no idea what this does)
|--- scrap (stores the variables you need for the recycler to know about the scrap)
| |--- computer (the actual scrap Item)

Say for example your recycler is very generic. It gives you some "points" based on the item fed in. A computer has more "points" than a sheet of metal, but less "points" than a rocket engine.

You would add the points variable to the Scrap class. Then subclass it into computer, and set the variable to say, 7 points. Do the same for sheet metal, which is say, 5 points, and the same for rocket engine, which is say, 15 points.

Then you put a sheet metal, a computer and a rocket engine in and array and feed it to the recycler. The recycler loops this array, casts everything to the "scrap" class if the type isn't already "scrap", then gets the points and adds them up. By the end of it, your recycler has added up 27 points.

teal junco
#

Oh hahaha I think we're agreeing I just poorly explained it by using a broad term "item" I apologize.

Your "scrap" was my "item" there.

#

Let me try it out real quick, I think we just have very different ways of explaining things 🤣

#

But I think we're on track

fluid pecan
#

yes, if scrap was a physical item you could scrap with the recycler, your way would be correct. To me, scrap is just a general term for anything that can be scrapped, not an actual item.

#

Basically, the lowest point you cast to is where it's just a concept, not a physical item in the world

#

You can also streamline this even more if you like with Data Assets, where you have no subclasses at all, and instead your actual items, like the computer, are a data asset that your "item" class holds and uses to populate it's own field.

So instead of a computer subclass, it's an Item class that has the computer Data Asset on it, where the data asset holds the mesh and the scrap value.

That's another more complex can of worms though, and not something I'd bother with yet.

teal junco
#

Oooh data assets might be quite clean. I'll look into it. Thank you so much for your help and patience! Haha

fluid pecan
#

No worries!
I still advise taking a quick skim of the aforementioned resources, it can clear up some of those terminology woes, especially where things have such similar names all the time. Who knows, you might even pick up something new!