Blueprint Communication with Custom Events
Hi there, Whenever I try to cast from one character blueprint to an actor blueprint to fire off a custom event, I run into a problem. I don't have an "Object" to cast to. I don't completely understand how the casting works. What am I supposed to put into the object section?
asked Jul 15 '16 at 08:24 PM in Blueprint Scripting
What a cast does is check a specific object or actor reference to see if it is of a specific type. What are you attempting to do specifically? Have you tried reading through our blueprint communication documentation, there is a wealth of information available that may help to explain the concept of casting, event dispatchers, and interfaces there:
For a basic explanation of casting ->
Think of it as if you (an actor) are asking a specific object or actor what it is. You have approached the object and said "Are you this?" Now, without a reference, you are still asking "Are you this?", but you have nothing that you are specifically speaking to. In this case, you will need to find a way to pass a reference of the actor you want to ask, either through a trace, object to object interaction, overlaps, etc. Once you have that reference, you can perform the cast, then use the "as " pin to get specific variables and functions from within the casted object.
answered Jul 15 '16 at 09:05 PM
OK, so casting only works with a reference to the actual instance of the object or class. Technically you can plug anything into there as its a wildcard, but it will only cast if its of the same class your casting too. If its not the correct class, the cast will fail.
In this case you'll want to add an instance of your GenerateEvenGraph to your game level, and then add a new variable based off that class in your BPCharacter class. You'll then need to somehow get the actual instance of the GenerateEventGraph class and plug it into that variable. This is quite tricky though and a lot of work, so we often do it a different way.
Instead of casting to GenerateEventGraph from inside your player blueprint, cast to your player from inside GenerateEventGraph and add to the LPoints variable. You can do this by casting to BPCharacter and for the object input, plugin the "Get Player Character" function. then as BPCharacter, just drag off to get the lpoints variable and do whatever you want with it. It is sometimes much easier to do this rather then the other way around.
answered Jul 15 '16 at 09:11 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here