Is there anyway we can have a generic cast node (like we get in C++) in blueprints to cast to the input class rather than hardcode the class we want to cast to?
I understand there might be some limitations from blueprints being more of a “scripting” language, it’d still be quite useful.
Yep, in which case if you create a new child, you have to remember to add the cast to the new class in that function!
I was thinking of using a wildcard output pin in a macro library.
But I’m guessing I might resort to one function per class or the cast waterfall just to keep it somewhat simple aha
Mmmh … I get your point. But imagine the following:
I have a parent class to roughly 5 classes. They’re all “singletons”, so I want to create a “get” function that would return a reference to any of the 5 instances based on an input parameter (which would be a class type). Now the only way I can see myself doing that is by manually adding a cast node for every class, which I don’t really want to do especially if I end up adding more than just the 5 classes.
If I could specify the class to cast to, I’d only need the one node. My only worry would be to get a reference to each instance to pass in as object.
Thing is, if you have to specify the class on your node like this, it is a cast. You had to supply the actor and class, just like you do with a normal cast…
Are you saying, you don’t want the hassle of figuring out which one of the 5 it is? That you can do something about…
Yeah, say I had an array of these objects (the type would be their common parent), I’d let the cast node figure out which one is the one that matches the class I want and return a pin “casted” to this class. I’m picturing this working like the GetComponentByClass node, you simply input the class and it does everything for you.
I think you need a specific example. You can’t have a function or macro that just returns a variable of the class you want. Unless you have one for each class, and you’re back to square 1.
But, for instance, if they all the classes had an integer variable, and you wanted to get that or set that. Then you can do that sort of thing: