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"

Pass a blueprint as parameter

Hello

I would like to know if I can pass blueprint as parameter in order to make similar object do different things.

Here is an exemple :

Imagine I have 100 buttons, each button as the exact same script because every button work the same way. But each button do a different action when they are pushed, some open door, others turn on the lights ...

What I would like to do is have 100 exact same buttons but with a blueprint script parameter Action. So that, when they are pushed, each button call their Action script passed as parameter.

This way I would have 100 exact identical button, and just custom script for action (like open door, activate light, play dialogue...).

In this way, I would have generic items and custom action that I could reuse everywhere I need.

The problem I have actually is that I can't find a way to pass a blueprint as parameter WITHOUT adding it to the scene. I'm forced to putt all the action on the scene and get a reference of the useless action in order to make everything works. I'm not talking about communication between 2 blueprint, i really mean passing a blueprint script as parameter.

For exemple in Unity, I can pass a c# script as parameter and use it within the script. How do I do that in unreal? I must use c++?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 12 '16 at 08:49 AM in Blueprint Scripting

avatar image

Crocsx343
32 7 10 11

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I don't think you can do this, not in a blueprint only project, and it's also very complex and inefficient to do in C++ project. Blueprint (as an asset, a.k.a UBlueprint) purpose is to generate a class (UClass to be precise). It's an asset that will not be included in the actual game, the one that is included is the class generated by the blueprint, if you create a function in a blueprint, the blueprint itself doesn't actually has the function. The point is, you should never save a reference to UBlueprint asset in the game, the only safe place to reference UBlueprint is in editor-only codes. If you're using Blueprint only project then you don't have to worry about this because the editor prevents you to do that.

There are lots of alternative and simpler solutions for your case, but the one I would use is the Event Dispatcher: Just create an event dispatcher in the button's blueprint and then call it when the button is pressed. Somebody else (a door maybe) can listen to this event and change its own state (from closed to opened or vice versa).

That way you only need to create 1 Button Blueprint and place this button as many as you like in the level, as for the Door (or any object that listens to the button), just create a property that reference to the button you've made, and set it to listen to the Button's event in its BeginPlay event script. The only thing that you need to do after setting this up is to click the door in your level, open/find the button reference in its details panel, and set it to the correct button it should listen to. (just like setting which directional light to use for the SkyBox)

more ▼

answered Jan 12 '16 at 09:38 AM

avatar image

Heapcleaner
521 15 5 19

(comments are locked)
10|2000 characters needed characters left

What you're looking for is polymorphism.

You make a base blueprint that implements the basics of the button. Then you make a function in the button like OnClick.

Then you can make derived versions of it that perform different things by overriding the OnClick function.

Or you can make an interface that actors can implement (Like IButtonTarget), and then make an array in the button of actors to activate. Then you can add the actors the button should activate, and then iterate that list and execute a function in the interface on each of the actors to activate on the button press.

more ▼

answered Jan 12 '16 at 02:11 PM

avatar image

MulleDK19
2.7k 161 274 254

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