For my fighting game, I would like to set up a select screen. The problem is I can’t seem to create references to characters without casting. That in itself wouldn’t be an issue if I could just loop through and cast dynamically to the one currently selected. I’ve tried creating reference variables but they’re all empty unless you cast to them and then pass in the reference variable–like what? Seriously? I have to get a reference to my reference before I can use my reference?. What’s really annoying is I only seem to have to do this to blueprint actors. Everything else can be manually set into a variable reference without casting. So…what gives Unreal?
I’d also like to avoid situations like placing every character into the world just to get a reference to it. There’s gotta be a clean way to do this internally. For instance the “Spawn Actor From Class” node has an embedded list of all classes that it pulls from. Why can’t I do that too?
its not really clear,
If you have all your character on the “Select level” and so you can see them all ,
from any blueprint you can get-all-actor-of-class and have them in a list to order them or tag them.
if you make them spawn instead of having them already placed
you can save their reference on spawning and then you can call event and stuff on them
If you dont have the 3D but only a widget with images of chars
you cant have a reference to the object that dont exist, you can set a reference to the class of the char. to do things like spawn or check which char is
Object reference is just a pointer to an existing object. Not the object itself. Therefore an object reference without an existing object is meaningless (will be nullptr).
If you just create an object reference variable, then it will be a nullpointer by default. You need to actually get an object reference from the world and set the reference variable with that.
You can only access functionality and variables of an object if you spawn it into the world. If you want to make information globally accessible, then you could use data tables. If you want functionality to be globally accessible, then you could use blueprint function libraries.
Get all actors of class only gets actors in the world. That means if I have 30 characters, I have to place all 30 in some level hidden off screen and then use get all actors of class to pull them in. To me this just seems asinine. Like, if you make a map. The asset exists in the content browser and using the open level function finds that asset and loads it into existence. I just want to do that for characters. To have to load all of them into memory seems silly. There’s got to be a way to select just the one reference, load that asset into memory, and then spawn it into the world.
I’m not trying to access it’s functionality before it exists. I’m trying to make it exist. I have a hard time thinking in bubbles because everything is obfuscated away. I have no idea how these bubbles are communicating. From my perspective, dragging a character from the content browser and placing it so it spawns into the world is magic. Somewhere behind the scenes there’s a check if the mouse is inside the object’s icon, it then gets a reference of that object (or the object itself) from memory, and then spawns an instance of it in the world. Prior to that action it did not exist in the world right?
So what I’m trying to do – click on an icon and spawn the character when the level loads. I can do it by casting to one character object reference at a time but I’d much rather have a list and only load the one needed rather than having to have a level with all of them already spawned in just so I can get references to them to spawn them in. Unreal is the ONLY engine I’ve ever had to do that in.
Granted, I CAN…have the character select as it’s own “level” with all characters dropped in somewhere off screen, get all actors of class, pass ALL of them into an array on the game instance, then get who I want from there and load that one in as the game level loads. But that method seems really asinine to me. Especially since the icon in the content browser is literally the object’s reference in memory but not in the world.