How to cast a Blueprint
Hello, I'm new to UE4 and Blueprints so I'm sorry in advance if the question is really obvious. I was trying to convert this:
To this something like this:
I wanted the target to be the mesh of the blueprint and not the mesh of the character, however, I don't know how to set it up so that it works.
Simply add a "self" node ( right click, type "self" ) and link it to the "object" pin of the cast node
i'm assuming the object it's called on a base class of "BP_VaseOk", if a situation can happens this code is run on something not of the good class you should add an 'if' on the success pin
if the blueprint the code is into, simply link the self node to the Static mesh composent node ( no cast required ) ( in fact in that case, you don't even need a "self" node, simply right click and type "GetStaticMesh" and you should find the correct node )
answered Jan 04 '19 at 03:26 PM
This falls into a category of problems I like to call the "wanna access this object thing from this other object thing" category.
Accessing specific objects from other objects is at the heart of Object-Oriented Programming, which is fundamental to how blueprints (and the whole of UE4) operates.
Anyway, wherever you're running your blueprint script, you need a reliable way to access the target actor (your BP_Vase actor) whose color you want to update. There are multiple ways to do this, and it's up to you to decide which is best for your use case.
Here's a few links to the official UE4 documentation on blueprint scripting that I think you'll find helpful:
Sorry I can't be more specific: there are just too many ways to approach this, and each offers different advantages. It's your choice, since you have the knowledge of how your project should be organized and designed.
I hope this helps anyway!
answered Jan 04 '19 at 05:51 PM
You are failing to cast properly. If you look at the first screen shot that works properly you will notice you first grab a reference to a specific object (owning player pawn), you then cast (ask the computer if the owning player pawn is of a specific type...."FPS_Character") when this cast succeeds (the "owning player pawn" IS a "FPS_Character") you now have access to the FPS_Character variables and can change the mesh material. Your second screen shot you fail to provide an "object reference" to apply the conversion into a BP_VaseOK thus this will never return any data to perform a material change on. Your other screen shot where you used "self" as the object fails because this is in a widget BP, and a widget BP is NOT a BP_VaseOK object. Your last screen shot again doesn't supply an object to do the conversion with. You simply have a "mesh" reference with no object that is why it requires a "target". Your issue lies in creating a proper reference to your BP_VaseOK object class. I have a tutorial that explains "casting" that you may find useful, I will post the link below. Let me know if you have any questions. (It is the first video in the playlist)
Follow this question
Once you sign in you will be able to subscribe for any updates here