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"

How can I set properties of a spawned actor before component signatures (like OnBeginComponentOverlap) are called?

The Problem

I need to set properties of a spawned actor before component signature callbacks are triggered - on both the spawned actor and existing world actors.

The Setup

I have a Minion class that extends Character. It has a SphereComponent with OnBegin/OnEnd overlap delegates to keep track of other enemy minions when they're in range of the minion. There's also a property that identifies the owner of the minion that is used to determine which minions are enemies of the owner. The component and signatures are created in Minion's constructor. The identifier is set manually from whichever class is spawning the Minion.

Example of the problem

I'll spawn a Minion from another class (GetWorld->SpawnActor), the constructor will execute, but it will also immediately trigger Overlapping events on existing nearby actors, as well as the spawned actor, before I can set the Minion's owner identifier.

Possible Resolutions

I could simply not rely on the dynamic properties I need to set (collect all minions and evaluate which to attack later), or create subclasses for each minion of each team, but I think both solutions are inefficient in the long run. I'm hoping there's some construction hook I'm overlooking, or I'd like to suggest the broadcasting of initial component signatures be moved to execute just prior to BeginPlay(), which will allow the class that spawned the actor time to initialize and set other properties of the actor.

Product Version: Not Selected
Tags:
more ▼

asked Nov 04 '14 at 11:21 PM in C++ Programming

avatar image

schmit
226 7 10 15

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

2 answers: sort voted first

I resolved this by setting AActor::SetActorEnableCollision to false in my actor's constructor and then later setting it to true (via the spawner class) once I've set the properties I need.

As BadderThanBad suggests, setting UPrimitiveComponent::SetCollisionEnabled to NoCollision prevents the overlap signatures of that component from triggering, however other components on other actors will still inherit overlap events from the component (based on collision response).

I believe an alternative is manually setting collision response channels to "Ignore" using UPrimitiveComponent::SetCollisionResponseToChannel.

more ▼

answered Nov 06 '14 at 04:42 AM

avatar image

schmit
226 7 10 15

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

You can avoid overlap events by setting NoCollision on your sphere components before binding the begin overlap delegate functions. Then later, in your begin play or whenever you are ready to have the events start firing, set the collision behaviour you want then. I think that should do.

more ▼

answered Nov 05 '14 at 03:42 PM

avatar image

BaderThanBad
664 21 18 177

(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