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 get collision events when I spawn an actor?

Hello, I'm having an issue figuring out how to generate overlap events when I spawn actors on other actors.

In my game, I'm spawning spells in the world. I keep a running list of the objects within the collision area of spells by adding them when I receive a NotifyActorBeginOverlap() event and remove them I receive a NotifiyActorEndOverlap() event. For the most part, this has worked pretty well and given me what I want.

My problem is that I have a category of spells that I'm placing as an area directly beneath the player's feet. Whenever anyone touches the spell's area, I need to know. The problem is that I have no idea who's in the collision area when the spell is spawned. If the player (or a creature) leaves the area and comes back in, I'll receive a begin overlap event as normal, but I need to know without having to leave the collision area and come back in. Also, as one would expect, setting the collision to block instead of overlap gives a notification, but stops the player from moving at all, which is certainly not desirable (players and creatures should be able to run over it).

For reference, I am using UE 4.9 and I am looking for an answer in C++, as I do not use Blueprints. Thank you for your time.

Product Version: UE older version
Tags:
more ▼

asked Jan 19 '17 at 03:43 AM in C++ Programming

avatar image

sseufert
54 5 20 20

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

1 answer: sort voted first

I reckon you are using a primitive component to do the overlap notifications, in which case I believe these are what you are looking for:

     /** 
     * Returns the set of actors that this component is overlapping.
     * @param OverlappingActors        [out] Returned list of overlapping actors
     * @param ClassFilter            [optional] If set, only returns actors of this class or subclasses
     */
     void GetOverlappingActors(TSet<AActor*>& OverlappingActors, TSubclassOf<AActor> ClassFilter=nullptr) const;
 
     /** Returns list of components this component is overlapping. */
     UFUNCTION(BlueprintCallable, Category="Collision", meta=(UnsafeDuringActorConstruction="true"))
     void GetOverlappingComponents(TArray<UPrimitiveComponent*>& InOverlappingComponents) const;

The actor.h class also has an overlapping components function, but I am not sure whether it works the same as the primitive component class functions.

     /** Returns list of components this actor is overlapping. */
     UFUNCTION(BlueprintCallable, Category="Collision", meta=(UnsafeDuringActorConstruction="true"))
     void GetOverlappingComponents(TArray<UPrimitiveComponent*>& OverlappingComponents) const;
more ▼

answered Jan 19 '17 at 07:06 AM

avatar image

cridia
815 30 26 105

(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