Custom Events - Again.... Widget Calling Actor BP to do something....

Ok i know it’s a fundamental thing to understand and maybe i’m just too thick to see it but what am I doing wrong?

I have my widget called “access_Work_3D” In this widget I click a button I want this button to make my Actor BP to change material, I tested the material change with a keyboard bind and it works so that isn’t the problem, I must be confusing the events / dispatchers / calling / binding terminology. please can someone point a thicko to a solution? I’ve even watched the 45min door Video breaking it down for dummies and I still can’t understand it haha! Ahhhhhhh

Widget BP

Mesh BP

Mate, you’ve got problems across both of these. To start with in the mesh BP you’re registering your custom event bindings within the custom event which you’re binding - they will never be called or bound(binded?). In the widget blueprint the first setter on the construct event will never have a valid target because the for each loop hasn’t fired - even if it had you’d only get the last element. There are more like the get all widgets node with the output unconnected.

The easiest way to do what you want is connect a get all actors of class (your actor BP) to the clicked event, then a get(0) from the returned list, then from that get reference you can drag off to call your mesh bp custom event, (showveil).

Get rid of the play and reverse nodes, just plug straight into the play reverse inputs on the timeline - also lose the binds but not the events themselves.

Thanks Dannington, can you explain in extra special talk for me the bit where you said “The easiest way to do what you want is connect a get all actors of class (your actor BP) to the clicked event, then a get(0) from the returned list, then from that get reference you can drag off to call your mesh bp custom event, (showveil).” I don’t have a clicked event in my Mesh BP unless you meant the clicked event in my widget BP? and getting a (0) from returned list i’m not to sure about either…

Never mind I got it!!! Thank you so much for your help, it’s so obvious now…

Dannington, would you mind explaining to me how the “get” function works in this context please? i’m getting my custom event and i’m getting it’s target via the “get all actors of class” but don’t see how it outputting into an array and then using “0” gets the correct target. I mean i’m happy it works lol just want to know how it works.

Hi ThinkTank,

Happy to explain. Using get all actors of class and get 0 is a bit of a rough way to accomplish the goal and you shouldn’t really use it. You need to use get all actors of class to get a list of all the specified actors in the scene - in your case you almost certainly have only one item in the array but the node doesn’t know that. In your case it’ll return an array with a length of 1 - you need to use get (0) to get that first item. Then you have a reference-able item which you can access and use.

TLDR; Step one: Get all items in the scene which are of the type ‘VAIL Blueprint’ - Step two: get the first item on that list (even though the list is only one item long).

A better way (not the ideal one still though) is on BeginPlay do the get all actors of class and the get(0) - then off that get do a promote to variable - then call that variable ‘VailBPRef’ or something - this variable is not a float or string or int, it’s a VAILBlueprint variable, it’s not even a variable really, it’s a reference or a handy link to that specific BP. Then you can use that variable/ref anywhere in your blueprint to call any custom events or access any variables contained within that BP. So when that variable is placed in your blueprint you’ll be able to drag of it and find any variables or custom events within that particular blueprint.

An even better way to do all of this is to register the reference in a handy place - an ideal place is to make your own playercontroller BP and store all of your ‘global’ variables and important references in there. You don’t need to do this right now but it’s worth giving it a try. When you do this you can put a GetPlayerController node in any blueprint you’ve made - then do a castto’whateveryou’vecalledyourplayercontroller’, then you can get at all of your global variables. On second thoughts, don’t try this last one unless you really want to know about what casting is - it’s really important to understand what it is though and I struggled with the concept when I first started.

Dan

Happy to answer any more like this.

Thanks Dannington - I think I understand the reason now. I am more interested in your method of using references in the controller and just getting it from there for all BP’s. I must have missed a important tutorial or two as I still don’t entirely understand referencing. I mean If I have a mesh in my level, I know that if I right click I can get it’s reference in the level BP. but never any other BP. so would you normally create all the references in Level BP then make them visible to other BP’s so like you was saying, then add a reference in to the controller?

I wouldn’t use the Level BP for that - you might make another level.

The player controller BP is good because it’s always there - you’ll need to make your own one and set it in the game settings - then you can go into it and make variables and arrays as required.

The thing to remember is that if you want to do anything to anything you need to have made a note of that item somewhere where you can find it - this might be an actor, material, widget - anything at all. If you don’t have a reference to that object then you won’t be able to perform any actions on it remotely (the object if it’s an actor or something can reference itself easily and perform it’s own actions on itself). The node GetAllActorsOfClass is a bit of a cheaty way of doing it - it’s like you’ve made a load of stuff but forgot to make notes and have to pick over everything in your scene to make your list.

The best way to do all of this is to make lists or arrays or in the case of single or specific objects single variables. I’ve got a project where I have 4 bases which can each create a tower made of cubes. On begin play my player controller spawns these 4 towers and copies their references to an array variable which is stored in that player blueprint - it’s a for/next loop done 4 times - spawn actor>add actor to array.

Each of these base objects has custom events which spawn a 3x3xwhatever tower made of cubes - these operate in the same way with a for next loop which creates each cube. - Each cube is added to an array which is held inside that base. If i want to access any one of those cubes from anywhere else I can do a:

GetPlayerController>castToMyPlayerController>get ‘Bases’ array > get(one of the bases) > get ‘cubes’ array > get the cube I want.

This is a brief explanation of casting: You might create 4 different ActorBPs - one is a door, one is a security camera, one is a monster, one is a street light. These are all different and contain different custom events/variables etc BUT AT A BASE LEVEL THEY ARE ALL ACTORBP’s, but the streetlight BP doesn’t have a custom event called ‘OpenDoor’ because it’s a streetlight etc. Imagine all of these objects laid out in a scene - you might have several of each. In that scene also you have another blueprint which is an overlap volume - it covers the entire scene. The overlap volume can return a list of everything in the scene - the array it returns is very broad in it’s scope as it has to contain all of these individual items. Imagine you wanted to open every door in that volume - you can do a for-each loop of every item returned in that volume (like the get(0) but for everything). The problem is you can’t just drag off the reference looking around for the ‘OpenDoor’ custom event because you don’t know if it is a door or a security camera or whatever. This is where you do a cast. You can drag off the reference and do a ‘cast to door’ - it’s basically saying ‘is this a door? if it is then you can have access to all of it’s goodies’ - you then get a cast reference to the door BP and a bool saying if it’s been successful or not and a reference to the item with all of the variables and custom events etc. Something you can do without a cast is set or get coordinates or anything else which is present on a ‘blank’ BP (I think).

For the GetPlayerController node you need to do a castTo’MyPlayerControllerName’ it doesn’t know that you’re using your custom one.

When you use GetAllActorsOfClass you don’t need to perform a cast because the node has already done it for you. If you promote the returned array to a variable you’ll see that the variable (in your case) is of the type ‘VAIL Blueprint’ where as the volume’s returned array will be of the more generic type ‘Actor’ (I think) - Your VAIL Blueprint is a type of Actor.

Sorry - I got a bit garbled towards the end there.