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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Alternative to casting every possible actor

Hi, I am looking for an alternative to casting to every possible actor. For example, in my scenario I have a character that can move freely. I have cover actor when character collides with, gets in to cover, I have collectibles when collided can be obtained automatically. And the list goes on. So here is my question. When collision happens, is casting to each possible act is a good way to maintain this or is there a better design for this?

Here is the example I can show. alt text

Thanks in advance.

Product Version: UE 4.21
Tags:
screenshot-1.png (71.6 kB)
more ▼

asked Jan 10 '19 at 12:32 PM in Blueprint Scripting

avatar image

HakanErunsal
39 3 8 12

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

2 answers: sort voted first

Interface. Set a Blueprint Interface with 1 function, like I_Collided or whatever. Set all your actors to implement that interface, and use the I_Collided event to drive your functions. In the Character BP, send an I_Collided message to the actor the Characted has collided with.

more ▼

answered Jan 10 '19 at 12:45 PM

avatar image

Tuerer
1.8k 12 7 8

avatar image HakanErunsal Jan 10 '19 at 02:28 PM

That was something I thought before but couldn't decide if it's the right design choice. Now I'll go and try it and see if it does do the job on different circumstances.

avatar image HakanErunsal Jan 10 '19 at 02:32 PM

What if I need to make different acts on the character itself depending on the collided actor? Like if it's a cover, take cover to that, if it's a vehicle, get in, if it's a collectible, collect it?

avatar image Tuerer Jan 10 '19 at 02:40 PM

You'll have to determine which type of the object that is. I'd use tags for that. E.g. On Event Hit you get the Other Actor's Tags, get Element 0, and Switch on Name. And depending on that tag you do the respective action.

avatar image HakanErunsal Jan 10 '19 at 02:46 PM

So in the end, I have to make something like this no matter which design I pick if cover, take cover, else if collectible, collect, else if vehicle, drive

avatar image Tuerer Jan 10 '19 at 02:51 PM

Yes, ultimately if you have several different actors you'll have to set some branches sooner or later. Even if you use interfaces, you still have to set a function in each actor, so it's basically the same, instead you do that in different BPs instead of one.

avatar image HakanErunsal Jan 10 '19 at 02:55 PM

I see. Thanks for the answer.

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

you still can use casting but in a simpler way.

Make generic Parent class that "vehicle", "collectible" and "cover_exmple" are derived from it, in the Generic_Parent class have the main generic functionality that is common between all.

Have a function in the parent class that returns a class type, which says what is the actual type of the parent class instance. then the followings will be your steps

  1. Cast other actor to the generic_parent

  2. Do everything that needs to be done for all

  3. call the function in the generic parent which detect and return the actual type of the child class

  4. cast it to the child class

more ▼

answered Jan 10 '19 at 12:57 PM

avatar image

plangton
357 17 20 31

avatar image HakanErunsal Jan 10 '19 at 02:55 PM

Thanks for the answer.

(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