About the Create dynamic material instance: I’m not really sure about this so hopefully someone can confirm or deny this, but I think that the material instance created in the tutorial is “shared” between all actors that has that material applied. So doing this for one character is fine, but if you will have that material instance on many characters, then you will want to create a dynamic material instance on each of them. The method of setting the parameters is then the same, but applies only to that actors material.
Sequence of events:
The character overlaps the sphere. This triggers the “OnBeginOverlap” on the collapse actor. It casts to FPC, calls its Set New Collapse Location Event, passing in the actors location.
When the Set New Collapse Location event is called, it passes the input vector to the vector parameter on the material.
The cast node serves in this case two purposes, one which is necessary and one that is pretty bad design. Lets start with the bad design one.
It is practically a query. If it is (player character) then (do this other stuff). For example, if you have projectiles, each projectile will also trigger this overlap event, but it will not (do this other stuff), because it’s not a (player character) and the cast fails. The reason projectiles trigger the sphere is that the collision preset of the sphere is “overlap all dynamic”.
In order for this to be well designed, you’ll want to change the collision preset to pawn, or maybe something more custom that all actors that can be collapsed share. Then projectiles and whatnot will not trigger the overlap.
What you want, is that only actors that can have this collapse effect can trigger the overlap event.
Then, even if you did change the collision preset, we still have to do a cast.
The (player character) is an actor. Its the actor reference the sphere overlap event provides. If we don’t cast, we can only access Actor functions and variables, but our function is in the (player character). so we cast to (player character). I don’t exactly know what’s going on under the hood, but if it is a (player character) then the cast succeeds and we can access functions and variables that the (player character) class has. If it is not a (player character), it fails.
Have 2 variables. One is an actor reference and one is a (player character) reference. dragging from their pins, you can only see the function we want in the (player character) variable.
But maybe the Actor reference is a (player character), we can then cast it to access the (player character) functions and variables.
In short, in order to access the function in the (player character) class, we must cast it to be handled as that class.