Download

Cast to a certain component within a blueprint

Hello!

I created a blueprint “FallDown” which contains 2 cube components. One is red. The other blue.
The blueprint is falling down and then overlapping a collision box.
This starts a particle fire.

It works with casting to “FallDown”.

But I want the fire go off only when the red cube is colliding.

How do I cast to the red box within the blueprint.

I did my research but I am not getting closer to a solution.

Any hints?

Thank you so much in advance.

Polly

(Ps. I am new to unreal and this is an excercise to understand casting better)

If both cubes are in the same blueprint you don’t need to cast at all.

Can you show the setup? ( the cubes and the overlap box ).

Hello,

maybe the example is not the best excerice :smiley:

I am just trying to figure out if its even possible to cast to the red box (or any other component) within a blueprint to ask if THIS certain componen from within a blueprint hit the collision.

Right now the collision spawns a fire on one cone and an explosion on the other.

Polly

Ok, but hold on, what’s a fall down? Can you show that? Thanks :slight_smile:

1 Like

The “FallDown” is a BluePrint I made. It looks like this:

In this case it is falling down. But it could also be a spinning thingy and hit the character or so :smiley:

And the red box should cause something different than the green box. But from within the same blueprint.

Ah… ok.

This has nothing to do with casting ( well, very little ).

Do you want to know what casting is for, or how to do this?

:slight_smile:

I watched a lot of youtube tutorials and from what I understood it is that in my case the collision volume asks if it gets hit by the “FallDown” Blueprint. If yes then it ignites the fire and so on.

And I wondered if its possible to ask if only the red cube inside the “FallDown” Blueprint hit the collision box and if yes then…

:smiley:

You’re right about the casting there.

Basically casting says ‘is this thing, one of these’?

But you can’t cast ‘inside’ a BP, it just tells you what kind of thing it is.

I’m just putting a demo together, which will let you know which cube is overlapping…

1 Like

Ok, so in this case, it makes most sense to do the operation from the point of view of the BP with the pair of cubes. Like this:

ezgif.com-gif-maker

There is a collision box around each cube.

I can do a version just from the point of view of the ‘sensor’ if you like. But that involves ‘component overlap component’, not casting, and is the hard way to do things.

1 Like

Thank you so much! :smiley:
Is it very hard from the view of the sensor?
I don’t want to steal your time but I am curious :laughing:

Just trying to get it working actually, it’s not pretty ( although I did actually use it in my game… )

So this is what you get the other way around. The upper text is the same as before ( what the 2 cube BP sees ), the lower text is what the sensor sees, ‘looking into’ the 2 color BP:

other way

The code in the sensor is:

See what I mean? Don’t do it that way… :wink:

1 Like

Thank you :smiley:
This looks very complicated but I will puzzle with it to learn how it works. The first example you made looks easier and lighter.

And the last 2 days I was trying to add a component from within the BP in the object slot of the cast node :smiley:

So you helped me a lot. Thank you :smiley:

Nope, that wont help… :wink:

It takes a while to understand what casting is for, and it’s NOT to communicate with blueprints :smiley:

You know how you have classes in Unreal? Different types of things. Casting does two things

  1. Tells you if you are faced with an item of type X

  2. Converts an item of type X into an item of type Y, IF ( big if ) Y is a sub class of X.

A lot of people get obsessed with casting, thinking it’s a way of talking between BPs, but you can talk between BPs fine with ‘direct communication’ ( as it’s called ).

Lot of very wrong tutorials on youtube about that…

You are right. I was thinking the same about casting. Like it is for communication. I will look into “direct communication”! I start to understand what classes are :smiley:

The thing is, very often you cast to check if an overlap is being caused by a certain kind of object ( like the player ). You’re not communicating with the player, you’re just checking, ‘is that a player?’

But: when you do that cast, you get a reference to the player ( if it was a player ), so you might as well use it.

That’s what leads to the confusion.

And the “cast to” node only checks if ifs the player or pawn and not if its the right hand of the player, right? :laughing:

Correct. Again, that would be easier in the player, because the player has all the relevant info.

If it’s really needed, the player can then tell the other BP, ‘hey, my hand just touched you’…

1 Like

Thank you! I will look into this next. Communication :smiley:

Get used to this guy, you’ll be using him a lot:

1 Like