What I want to do is have an effect happen in a material when I click on a mesh.
Here’s what I have so far:
How can I make an effect that starts as a solid circle, and expands outwards with is no longer being solid, like this:
Imagine a rain drop on a water surface expanding outwards.
EDIT: So, I was missing a keyword to get my “circle expanding” effect… Ripple. Once I searched for that it was easy. However, now I am having issues getting the effect to happen only where I click… How can I do this? Here’s what I have so far:
I would probably do this using Worldposition. If you do WorldPosition - HitPosition that will automatically give you a world basis centered around the impact point. That also bypasses any UV issues.
Simple cosine then biasscaled into the 0-1 range would get ripples, or you could build a single expanding ring mathematically by using the distance node and some expanding offsets. Kind of like a sphere mask that is soft on both sides.
In the name of honesty, I have no idea what you just said!
Haha… But you are saying it’s possible to change where an effect is on a material in real time? After doing hours of research, I am starting to think that it isn’t possible to actually change the material in real time, only the mask using SphereMask… So, the effect will always play in the same spot. The video I am trying to recreate (UDK - Shield Effect - YouTube) apparently doesn’t actually change the material in real time like I thought it did - it spawns an entirely new sphere, and somehow changes the position the material is facing, and then deletes the sphere.
So, I guess I’ll take that approach too. So what I need to figure out now is how to change the position of the material…
Could you possible explain how materials work, in terms of how they are created/updated? Why did the guy decide to spawn a new sphere, is it because materials are unchangeable once spawned?
Thanks for the reply and I hope I am making sense…
WorldPosition is simply a node in the material editor. Its called “Absolute WorldPosition”
HitPosition would be the result of your blueprint linetrace hit location. You would feed that from the BP to the material by using a VectorParameter. To control the material via BP you need to create a “Material Instance Dynamic” (MID) for your sphere object and then do “set vector parameter” and set the HitLocation to equal the hit location of your line check.
Yes you can easily update the location of the hit afterwards by doing “Set VectorParameter” whenever you want. But you probably don’t want that. If do you that, any bullet hit will start your effect over from the beginning in the new location and any in-progress effect will vanish. There is no way to add multiple ripples without having separate parameters for each ripple and knowing which to control. That is potentially messy to set up and you’d still have some max number.
Adding a new sphere for each instance allow each version of the effect to keep playing to completion so they multiple ripples overlap instead of resetting each hit. Does that make sense?
To get an animated ripple, you could use a Timeline in blueprint to drive another parameter. To do that you simply make a timeline and on “update” you do “set scalar parameter” on the MID again and control another parameter in your material.
That is most likely because the preview mesh in there is going to be fairly small. So whatever math you are doing for units is probably very different at the two different scales.
I would avoid tweaking the settings for that view and instead place an actual mesh of your typical size in the world and tweak for that.
Then just give the location a good default location (ie, place another actor at your desired test spot and enter those location values). You should be able to scrub scalar parameters in the material and see them update in the world without having to compile the material.
The issue was the SphereMask hardness was too high (for in-game, not the material editor). Maybe I misunderstood but changing the sphere size did nothing. But fixing the hardness worked, so it’s all good.
You’re awesome man! Just one question regarding what you told me… Did you mean to create a material instance and change that in order to see in materials changes update in the world in real time? That’s what I did but I think you may have meant something else.
You can do both. A material instance will certainly be smoother to scrub, but a regular material should also update after you change a setting in the base material without compiling. Unless that value was already overwritten by a material instance of course.
Hi,
To get the position is something that should most likely be done in the Player pawn blueprint. If you look at the ContentExamples project you can see how we did this in the “PlayerCharacter” blueprint. It’s a function called “CheckTrace” that gets fired on LeftClick. You can see the location info starts with the player camera to setup the trace. For a gun you may need to get the location from the gun tip depending on the desired behavior.
The trace returns HitResult which contains the world location of the hit. You can also extract the “actor” and check for “tags” which are added to components in BP or actors details panel. By filtering by Tag you can build in the response to various object types into your Pawn and then cast to the appropriate type to interface directly.
Thank you for your response. I fear my question was inaccurate, my problem is not that I don’t know how to get the hit position, but how to offset the effect inside the material.
I didn’t really know what to do until I also used a UDK example, but I was still not able to make it work. The effect doesn’t look like it should…maybe I am only tired, I have to take a second look at it today.
Shall I open a new thread if I am not able to figure the problem out or shall I post it here?
Okay most of it works now, but I wasn’t able to place the ripple effect on the right position, there is something I just don’t understand…please post me an example, I just don’t get it how it works…
and the second problem is, that it flickers, because I don’t know how to let the ripple fade out. Please help…
Then you need to replace the constant “0” with a VectorParameter. That is the location of your hit. It needs to be provided by a blueprint line trace. Then you use "create material instance dynamic "and then “set vector parameter” to the location of the hit.
You need to re-read the earlier replies in this thread. We talk about the resetting problem in detail and why the original example chose to make a new sphere for each bullet impact.
For the masking by distance that is really easy. In fact the answer is looking right at you from the images in this thread as well. Look at the top image of my last post. Nice distance based mask from the original location. Just multiply your final ring by that single sphere mask and it will do what you are asking.
I had the same idea - to spawn a new sphere for each bullet impact - that’s why I didn’t read it because I already knew, when I wrote it, that I could do it that way (but I should have read it, I know), in addition I thought maybe you had a different idea, so I just asked…