I need to take the variable of another blueprint so i used cast to…but i nedd to connect object to…what i have to connect to the object?
what is “HudTimer” for a class? What is the BaseClass of this? Then i can tell you what the Object needs to be.
You need a “created” UObject for this “Object” pin. That could be a spawned Actor. Like your Character, a HUD, a GameState etc.
Or also an Actor you created yourself, like a Button or so.
But this highly depends on what “HudTimer” is. Because, for example, casting a Controller to a HUD brings nothing. It will just fail.
With Casting you make sure that the Object you cast is of the type you are casting to. The cast will only work if the Object is of
that type or if it is a child in some chain of that class/type. And it is used if you want to access variables that are only available
in that class or its childs.
Child of PlayerController: FirstPlayerController | Has a Variable called “FirstVariable”
Child of FirstPlayerController: SecondPlayerController | Has a Variable called “SecondVariable” and the “FirstVariable” of its Parent.
If you, at some point, get a pointer to a “PlayerController” and you want to make sure it is of Type “FirstPlayerController”, you gonna cast it.
If the cast works (needs to be of type First- or SecondPlayerController, otherwise it fails!), you can access the “FirstVariable”.
If it is “SecondPlayerController” and you want to access the FirstVariable, casting it to the FirstPlayerController is enough. If you want to access
the SecondVariable, you need to cast to “SecondPlayerController”, which will only work if the Actor is really of type “SecondPlayerController”.
Both of these classes can be casted to “PlayerController” but you can’t access the variables with this cast. You can only make sure that they are
PlayerControllers in one or another way.
If you don’t understand this, i highly recommend you to learn “c++ inheritance”. Not the code form, but the logic behind it. Blueprints
are C++ and you need to understand the basics (:
hudtimer it’s a hud xD that spawn a timer in the top right of the screen
Then use “GetPlayerController” and with the return value you use “Get HUD”. The return value of GetHUD is the Object you need.
thanks for the help
and if i have to set the object of a cast that is a light(that go off after X seconds)?
i don’t understand what i have to set at all this cast
You want to cast an object to a light, so you can access it and turn it off?
Where is your light? In the game somewhere? How do you access this light?
Line Trace? Overlap?
You could, for example, use a LineTrace when pressing E and if you hit something (the light at best)
you can use the “HitActor” of the HitResult als the Object you need.
at X seconds my light setted in the map go off…in that moment a boolean begin true… now in another blueprint, that of the sound of this light(sound and light are for a generator) have to stop…so i need to cast to the light blueprints for take the variable of the light…
Then you need a reference to either the other Blueprint or to the Light.
If they are spawned in the Map before runtime, you can get them either in your LevelBlueprint,
or you fill them directly.
Let’s say you have a Light and a Sound Blueprint. Both are placed in the Map. In your SoundBlueprint,
you create a Variable with the Type of the LightBlueprint. This Variable is empty at the beginning.
In the options of this Variable hit “Editable”!
Now, in your scene, select one of your SoundBlueprint actors. On the right side you will see a Details panel. Search there for the
variable you created. Next to the variable, there should be a pipette symbole, click it and then click the Light that you
want to connect the Sound to. Now you can access the Light in the Sound Blueprint.
thanks i solved in another mode…i added an audio component to the light thanks for all