Direct Blueprint Communication issues within "MyCharacter" Blueprint!!!
I'm getting some errors and don't understand why. Here's the situation....
Within my "MyCharacter" blueprint I've created a variable called BP_Basketball that references a "basketball" blueprint I've created. This basketball BP simply has a sphere root component and a mesh component to represent the ball.
In my "MyCharacter" blueprint I've created functions to attach the ball to my character as well as "shoot" the ball (the "attach" function is seen in the screenshot). HOWEVER, after I play in editor and exit, I always get these errors (seen in the screenshot). I KNOW it has to do with the BP_Basketball variable somehow (because if I bypass the whole "set collision" aspect within the "Attach Basketball" function, then I do NOT get the errors).
I just DO NOT UNDERSTAND why I am getting errors here. In general, I seem to be having a hard time with accessing variables and whatnot from other BPs within my "MyCharacter" blueprint.
What am I doing wrong?
asked Apr 07 '15 at 05:17 AM in Blueprint Scripting
That variable needs to be set from a cast node, and the ball needs to be in the level when that cast and set happens. Can you show where your variable is being set?
EDIT: Another, more comprehensive answer given based on your questions.
Casting gets the particular instance of a blueprint. Simply creating a variable based off a blueprint is not enough; you must reference the actual object (instance) that is currently within the level. When you do a cast, it is only necessary to do it once, because:
Once you have the new variable that contains the instance, you are able to use that variable from then on to utilize any events, functions, or public variables (if you don't see a variable you want, go to that BP and set the variable to editable) that reside within the instance's blueprint. Anything you do will affect ONLY that instance, so you could have multiple instances of the same blueprint doing different things.
So here's a couple methods for casting. First one involves using a Get All Actors of Class node that will return all actors of the class you specify. You use Get to grab a particular one of the returned array. If you have just one in the level, you're good. Otherwise, you would specify which one by setting the integer value of the Get. Once you have your object, you can then do a Cast to [class of the thing]. Finally, from there, you can drag out and select Promote to Variable to save the instance.
You can then use that variable to access whatever you need. You also do not need to recast if you need to use that variable at some point further along in the processing order.
Here's an example that involves casting from an overlap. You check the actor class to make sure it's the right type of item, and then cast to your actor with the result of the overlap.
And since you mentioned that it's a ball and probably want some physics happening, here is the method for altering the physics of an object in real time. You can't enable/disable gravity and physics on an entire actor, because those properties are based on the components of the actor, and specifically the root in almost all cases.
Take your instance variable from earlier and use Get Root Component. Now, use that to Cast to Primitive Component. You now have direct control over its most basic properties. You can save that as a variable as well, which lets you use that in later processes to control those properties without recasting.
answered Apr 07 '15 at 08:21 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here