Changing Overlay Material Max Draw Distance?

So I have a setup where I am spawning 20ish actors from the same class using a line trace to put them randomly in an area around the player (Line trace into spawn actor, looped 20 times). I have a button that turns on an overlay material so the player can see where the items are. At the start of the game I want it to randomly decide how far away the player can see the overlay from (Max Draw Distance).

But when I set it up it doesn’t seem to be changing the distance at all.

Here’s what I have for trying to change the overlay material, it’s probably not well set up but it’s the only way I could think to do it.

If I place the actor that is using the overlay into the world, the draw distance change works. But if I try it with the spawned in actors it won’t change anything.

First, in this loop it seems “keen_eye_stat” variable is in one state (0 or 1).
That means all meshes will be 1000 or 2000 max draw distance.
No idea what set overlay material max distance do.

That’s intentional. I’m trying to get it to set to 1000 or 2000 (there’s more to the right) depending on if the Keen Eye Stat is 0, 1, 2, etc. It’s working when placing the actor directly into the level but not when it spawns them in with the Spawn Actor node.

The code wiring is a bit messy, sorry. Basically it’s looking at the mesh to change, checking if Keen Eye Stat is set to 0, and if it is sets the distance to 1000. If it is not 0 (false) it goes to check if Keen Eye Stat is set to 1. If it is, it sets distance to 2000. So on, so forth. Likely a bad way to do it but it is working if I put the actor directly into the map.

(Setting overlay material max distance changes how far away you can see the outline from the overlay material)

Where is this code executed? Level blueprint? On begin level? Need more context.

It’s in the player blueprint.

Do a print string at the end of set overlay material max draw distance. Does it print string.

It is not giving the message from print string at all.

Put print string right at the beginning of loop body.

I’m so sorry my dumb butt forgot I have multiple outcomes. Print string at the end of the max draw distance DOES return a message.

The same number as number of actors?

If I drag out of Array Index in for each loop to connect to the print string it should show me the number it gets right?

Maybe. Try it.

Wait hang on this helped I realize I have it connected to begin play not something like event tick, so it’s only setting it at the start of the level before the berries spawn not any time the berries spawn. If I set it to event tick it returns all the actors as they spawn! I feel so dumb. Let me check if this is actually changing the distance or not…

Edit

Yes this is working! The answer was I was connecting it to the wrong thing. Thank you so much!!

Static mesh?

No I had the whole code on Begin Play, so it was trying to set the draw distance of the non existent actors before they spawned. I set it to event tick (for now, might find a better solution later) and it now sets them any time they spawn.

Thanks again! The print string helped me figure that out.

Glad you figured it out. Only do this loop when you need to(if you are doing it on tick(like when you change"keen eye stat" variable state or something)).
Also, either give a 0.3 seconds delay OR check if all actors are actually spawned before you do this loop. That’s all.

1 Like

Yeah the event tick is a temp solution, I’ll likely trigger this code on the use of the Keen Eye ability so it’s only running once when the ability is activated

1 Like