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"

How do I save an actor as a variable in game and then spawn it in a new location?

I'm a bit newish to the C++ side of Unreal, but I'm trying to expand my knowledge on it a bit. What I'm trying to do is have an actor that is hit by a line trace be "copied" and destroyed, and then on the next shot place a copy of the actor that was originally destroyed. I'm also wanting to make it so that a second actor can't be copied/destroyed until the first actor has been placed. Essentially you can only "carry" one actor at a time and must set it down before picking up a second. I'm using the default C++ First Person Template and here's what I have so far:

The ActorStored variable begins the game as false. When it is false and the line trace hits an actor, the actor's name is displayed on the screen (for testing), the actor is destroyed, and ActorStored is set to true. While ActorStored is set to true, nothing will happen if another actor is hit with the line trace. After the first miss by the line trace, ActorStored is set to false so the cycle can begin again.

What I want to have happen is when the line trace hits the first actor, a copy of that actor is saved to a variable before it is destroyed. Then when the line trace doesn't hit anything, it would place a copy of the saved actor at the end point of the line trace.

What I think I need is a variable for the actor (AActor I think in C++?), and then code to spawn that actor at the end point of the line trace when it misses. Alternatively, I think it might also work to spawn the actor at the impact point on a hit, but I'm unsure which is easier. I've tried messing around with both, but I couldn't get either to work.

Here's a copy of the code I have so far. It's in the OnFire function in the First Person character class.

alt text

Product Version: UE 4.21
linetrace.png (53.9 kB)
more ▼

asked May 19 '19 at 08:49 AM in C++ Programming

avatar image

5 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
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