What do I put into the object part with the cast to actor.
Casting is a way of checking if a reference you have is of a certain type. So, you need the reference firstâŚ
You canât cast without a reference.
some nodes will pass variables without knowing what those variable types are. They move those variables around at the lowest level, which is Object if Iâm not mistaken.
Once you get that Object from some other node you use the Cast node, which will try to use that Object as the type you have selected in the Cast. If the Object matches the Cast type, you can then use it to do some other stuff. If not the cast will fail.
is simple to understand if we take this example.
You have a Dog and a Mouse. Both are Animals. In this example the Animals is the base object, the Object from unreal.
You have a node that provides an Animal out of it. He doesnât care if is a Dog or a Cat. It just gives Animals.
Lets say you want a Dog. Once you get that Animal you Cast to it to see if is Dog. If is a Dog, cast is successful. If is a Mouse then the Cast fails.
I understand how it works I just donât have a clue what thing I need to put into the object part of the blueprint. I donât know which part of something I get it from whatever it is I need anyways.
I think you are missing part of the concept of how it works.
Casting is not to get a reference to something. A lot of people think âI need to cast to the playerâ, for instance. Wrong.
Casting is to âunwrapâ something, to find out it itâs the right type. Or, to convert to the right type.
So, for the player, you would do âget player characterâ and cast it to your sort of player.
What are you trying to cast to?
for example a âFor Each Loopâ with an array as input will throw out Objects even if you clearly give it an array of a certain variable type.
So you need to cast on the array output object to get the variable type back correctly
for example a âFor Each Loopâ with an array as input will throw out Objects even if you clearly give it an array of a certain variable type.
So you need to cast on the array output object to get the variable type back correctly
This is not true at allâŚ
sorry for the confusion created. In some cases the for each loop will get back a list of objects as in the example bellow. Iâve worked with this loop and Iâve wrongly assumed all for each loop will do this. I mean technically is not the loop fault because you give it an array of objects.
sorry again, I think the message still apply. if you get an object out of something you need to cast it to get the type back
I have a random number string variable that is stored into a blueprint and I am needing the exact same variable in a different blueprint aswell to be able to move the player to a certain location depending on what the random number is. if it is one then it moves one space forward, 2 it moves 2 spaces forward etc.
yes ok but i still dont know which object or what i need to put into the object part of the cast
you make the variable visible outside the blueprint, using the eye option near the variable name. then you get a reference to the blueprint itself. Then you can drag a line out of this blueprint and type get âvariable nameâ. no need to cast anything.
except maybe cast to the blueprint when trying to access it. how youâve got a reference to the first blueprint from the second blueprint?
The root of this question does not revolve around casting. Casting is a test + conversion. You have issues with obtaining a reference.
i still dont know which object or what i need to put into the object part of the cast
Neither does the editor - what if there are 3 identical objects? How is the editor supposed to figure out which one you mean⌠Obtaining a reference is your job.
If youâre 100% sure there is only 1 of each of those and you could not care less about blueprints comms, you can Get Actor of Class
- you wouldnât even need to cast. But this is a ham-fisted solution. Next time you need to do any kind of comms, youâll be stuck again.
To do it right, youâd need to explain how those 2 blueprints make it into the game?
- are they placed in the level
- are they singletons - parts of the framework (player controller, pawn, game instance)
- are they spawned dynamically (if so - who, when and where spawns them, what is referencing them to start with)
Once we know how they are instantiated, we can connect them.
For Loop takes a wildcard. You feed it a type, it returns the same type. Async spits out a type, the loop processes it. Donât blame the loop :D. You must cast here.
Have a look at this infamous behaviour:
The order in which you connect the wires matters.
I am so confused because i am getting people telling me multiple things that i have no idea what it all means and all i need to know is how to see if the number from a variable in a blueprint matches the source variable in another blueprint. eg. the string in the source is the number 1 and i need to know if they dice_number string value from another blueprint is the same as the source (so i need to get the value of dice_number into a different blueprint). so just what the string will output if i print it nothing else.
Your question is impossible to answer directly - you have not provided enough information. We feel exactly the same as you. You want to connect something to something without knowing where to look for those thingsâŚ
What & where are those blueprints? How do those actors get into the game:
- how to see if the number from a variable in a blueprint - what is that actor and where is it?
- the source variable in another blueprint. - what is that actor and where is it?
Did you Spawn an Actor from Class
by any chance? Did you drag it from the Content Browser
into the level blueprint? Perhaps one of the actors is the Game Mode
or maybe you keep the variable in the Level Blueprint
already?
We donât know so we can hardly advise without giving you some overall, generic answers.
I am so confused because i am getting people telling me multiple things that i have no idea what it all means and all i need to know is how to see if the number from a variable in a blueprint matches the source variable in another blueprint. eg. the string in the source is the number 1 and i need to know if they dice_number string value from another blueprint is the same as the source (so i need to get the value of dice_number into a different blueprint). so just what the string will output if i print it nothing else.
sorry , weâve got on a tangent and got over your thread.
I suggest watching this section of the website
there are great tutorials that you can watch to understand how this works. what you want to do is basic stuff and is best to watch the explanation in a video instead of reading stuff here on forum.
just chose âfor begginersâ option to get the basic stuff displayed
there isnt a tutorial that is about my problem
there is hundreds about your problem. just take some time to watch them. game dev takes patience.