x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Light follow my character?

Hello! I want to make a script; when my character enter trigger box - light start follow you ( like a flashlight turn on). How can I make it?

Product Version: UE 4.16
Tags:
more ▼

asked Sep 20 '18 at 10:49 AM in Blueprint Scripting

avatar image

NewMan2332
28 2 1 5

avatar image ThompsonN13 Sep 20 '18 at 01:36 PM

details bro, you need to provide more in your questions. does the light already exist? is it like a spotlight? if its like a flashlight where is the light coming from? theres many things you didnt mention so we are left to wonder.

this is probably a wrong assumption, but assuming its a spotlight and it doesnt already exist in the world then you would just need: on actor begin overlap -> spawn actor from class Spotlight (location: player location +300Z) -> attach to player character.

avatar image NewMan2332 Sep 20 '18 at 03:14 PM

Yes. Like a flash light. The light doest exist yet. I want the game to make a light source attached to the character when I trigger the box (overlaping) it is like to turn on a flashlight without pusing down the key, But overlaping the triger box.

avatar image NewMan2332 Sep 20 '18 at 03:15 PM

I tried as You said. Light source bean spawned But it is not attache to my characte...

avatar image NewMan2332 Sep 20 '18 at 03:24 PM

I just want to make certain area around the character vissible in the dark

avatar image Nebula Games Inc Sep 20 '18 at 05:42 PM

What @ThompsonN13 said. Just spawn a light actor you can use "attach to actor" and place it wherever you want. Not hard to do at all.

avatar image ThompsonN13 Sep 20 '18 at 09:54 PM

theres basically two ways to go about this, you can either create a new light or have a light setup in the character and toggle its visibility.

the first picture below shows the first method of creating light, settings its location, and attaching to the character. the script i setup here creates the light when you enter the volume then if you enter it again it destroys the light. a simple on off kind of thing.

the second picture shows the second method mentioned where the light is added to the character beforehand then you just toggle its visibility. this is a much simpler script to write and setup but has its limitations since it needs to be setup beforehand.

alt text

alt text

capture.png (263.7 kB)
capture2.png (76.3 kB)
avatar image NewMan2332 Sep 21 '18 at 10:18 AM

Thanks! You helped a lot. I will use second variation.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

It's different from what the other guys here have recommended, and I don't know if it's the best practice way to do it, but I was able to achieve what it sounds like you're trying to do with the following:

  1. In the Blueprint for your character, add whatever kind of light component you're wanting to have appear and position it where you'd like it to be relative to the character. You'll probably want to test that in gameplay first and make sure it looks the way you want it. That includes playing with the intensity setting in the details panel to figure out how bright you want it to be (remember that, it'll matter in a minute)

  2. With the light selected in the components panel, go over to the details panel and set the intensity for the light to zero. Then, in your event graph, create a custom event (if you don't know how, just right click, then type "cust" and the option will appear). Select that and name the event what you like. Drag off the right and type in "set intensity." Should see the option come up with the light you created named in parentheses. Select that. Inside the function, next to "new intensity" enter the value for the brightness of the light you decided on earlier. Compile and save.

  3. Create your trigger in the game world if you haven't already. Select it and over in the details panel go to "edit blueprint." Enter a name for the BP and save it wherever you like. With that done, on the event graph delete everything but the ActorBeginOverlap executable. Drag off it and type in "valid." Scroll all the way down for the "? IsValid" option and select it. Drag off the right of the "Is Valid" output and just release. When the search box comes up, uncheck the "context sensitive" box in the upper-right. Then in the search bar enter the name of the custom event you created for the character and an option should come up for it. Select that.

  4. The two functions you made are going to need to know what BP they're interacting with, so go over to the variables section of the "my blueprint" panel (you should still be inside the BP for your trigger). Select the button in the upper-right to make a new one. Name it whatever you want. Back over in the details panel, you'll see an option for variable type. Select this and start typing in "first-person character" or whatever the character type for the game is. You'll see its name pop up. Mouse over it, then "object reference" and select that. Directly underneath that section, check Instance Editable. That'll be important in a minute. For now, back over in the variables section hold Control and drag off the variable you just made into the event graph. Connect that to your "input object" and "target" pins on your nodes in the graph (the single reference you made will connect to both). Compile and save.

  5. Go back to your world view and make sure you have your trigger actor selected. Over in the details panel, under "default" you should see the name of the variable you made, and next to it a drop down box (this was why you checked "instance editable" earlier, or you wouldn't see that). Select that, and you should see the name for your character's BP. Select it.

You should be finished. When you start play, the light is technically part of your character, but not on. When you overlap your trigger, it's going to activate your custom event on your character and turn the light on for you, then since it's a part of the character it will follow you from there. If you have any issues with this still let me know and I'll try to help. Sorry for the lengthy reply but wanted to be as specific as possible to make it easy for you. Hope it helps. Cheers.

more ▼

answered Sep 20 '18 at 10:11 PM

avatar image

IIIDysphoricIII
56 1 1 6

avatar image NewMan2332 Sep 21 '18 at 10:19 AM

Thank you for this valuable information. I will definetly practice it!

avatar image IIIDysphoricIII Sep 23 '18 at 05:48 PM

You're welcome

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question