Set Vector Parameter from Blueprint

Hi, I’m hoping someone can point me in the right direction here. I followed this great tutorial:
http://eat3d.com/free/ue4-shader-fx-volume-vertex-collapse

and got the shader set up fine. It’s applied to the third person character; when you run the character into the center of the effect all of its vertices collapse until you run the character out again. However, to set the position of the effect one must set values for the Vector Parameter that controls its position in world space.

I’d like to be able to set those Vector Parameter values based on the location of an object (like a simple sphere) in my scene without having to copy/paste values from the sphere to the Vector Parameter components of the shader.

I set up a Blueprint for the simple sphere that I hoped would do the trick but so far no joy. Can this even be done? At runtime I want to set values for the Vector Parameter based on the location of the simple sphere in the scene. I don’t wish to apply the shader to the sphere, just to control the shader’s position in world space with another object in my scene. I can do this pretty readily in a 3D package but no so in Unreal.

Any advice or insight would certainly be appreciated.

Do you want just one of these collapse points in a level, or many?
In any case, this will work with either.

  1. your character blueprint needs a function, or event, that updates the vector of the vector parameter in the material. That is done through the “set vector parameter value on materials” node, and it must be an instanced material. Which you should have, if you followed the tutorial. Its name is that of the vector parameter.

  2. we create a new actor whos purpose is to represent and update said locations. All we need for this is a collision sphere. when it overlaps with the character, it calls the characters function and passes in its location.

At least, that’s how I would do it. You could have the overlap event on the character, up to you.
There are a few things to keep in mind with this design.

  1. There should not be many (or even two) collapse actors close to each other. The sphere overlap radius should never overlap, in fact there needs to be at least a character width between each.
  2. The sphere overlap event simply “tells the character there’s a collapse point nearby”. The radius should therefore be bigger than the collapse effect.

Thanks so much for your helpful response, that did the trick! I created the event inside the blueprint for my “placement sphere” (which was not a collision object) and tried triggering it with both an Event Tick and a BeginPlay but neither worked. I also thought I was supposed to use a Create Dynamic Material Instance to change values on material parameters, so it’s nice to know about Set Vector Parameter on Materials.

Hope you don’t mind my asking - so in effect, what’s happening here is when the player overlaps the sphere volume, the “Set New Collapse Location” is triggered and sends data and an execute command over to the “Set New Collapse Location” event in the FirstPersonCharacter? The “Set Vector Parameter Value on Materials” function is fired and sets the Parameter Value (“Location Vector”) that is associated with the FirstPersonCharacter? Just trying to sort out the sequence of events.

And I’m still not clear on what the Cast… nodes do. In this case is it used to “Send” the “execute signal” over to the FirstPersonCharacter “Set New Collapse Location” event?

Thanks again for your help!

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.

Thank you for this helpful explanation, Ste1ner! I have a better idea of what casting is now, so thanks for taking the time!