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"

Is there a way inside an actor to keep a reference to another actor?

I thought about using a simple pointer to an actor, ATarget, inside the big, main actor, ACannon, to keep track of ATarget's position.

But it seems that the traditional C++ way of instantiating a ATarget class object with a constructor inside the ACannon constructor isn't the right way to do. When initializing the ATarget in the ACannon's constructor, it failed to do so with the use of ObjectInitializer.

Could anyone give hints on what I should do here instead? Thanks in advance.

Product Version: Not Selected
more ▼

asked Apr 03 '15 at 02:10 AM in C++ Programming

avatar image

293 31 30 91

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

1 answer: sort voted first

Constructor only valid for create component for the class, all the reference actor instance need to be create at runtime. You should put that instantiate in BeginPlay(). If not, you can add a ChildActorComponent in the ACannon, and set class to ATarget.

more ▼

answered Apr 03 '15 at 02:21 AM

avatar image

Duncan Dam
3.1k 121 50 164

avatar image asperatology Apr 03 '15 at 06:38 AM

Could you show me an example of instantiating in BeginPlay()? This is just in case I wasn't able to use ChildActorComponent for specific reasons, and I wouldn't know of any other ways to instantiate actors. Thanks.

avatar image Duncan Dam Apr 03 '15 at 06:49 AM

Ok, you can use GetWorld()->SpawnActor to spawn your ATarget in ACannon.


Check this one if you have problem.

avatar image asperatology Apr 03 '15 at 08:23 AM

Thank you.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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