I dont understand why the “isValid?” check in the 3rdPersonCharacter project is returning non valid and valid at the same time. The character indeed uses the animation blueprint in which this check is made.
It actually flickers constantly between valid and not valid (see screenshot). So the rest of the code executes fine but it is still failing constantly at the same time.
The project is the literal default project (with starter content), created 2 mins ago. I dont understand what I am missing here… (I figured the problem in another project, with casting failing when it should not, and succeeding at the same time)
I cant upload my screenshot in here for some reason, here is the link : Screenshot by Lightshot
I’m not sure why it might flicker that way, but Try in function name suggests that it might fail sometime. The better way to make it reliable is to get pawn on BeginPlay and store it a variable. Then use that variable in code.
In the link GameState is a variable in blueprint, the function is Pure, and whenever I need to get gamestate I use the function. Function validates it and if ok, it returns it unchanged. If something is worng, then it gets gamestate from a default method, then casts it to my type (you don’t need it) and stores in a variable so next time I call this function I just get already stored gamestate.
You should confirm that it is the same object, because in the animation blueprint preview window, the pawn will not be valid, so if you have them both open at once you may be seeing the prints from different contexts
In my example (the default project) I would still need to access the Character actor on every frame to update the animation. I dont think I can simply cast to the Character on begin play and then access its value whenever I want, the data stored is outdated in the next frame (velocity change for example)
If I understand correctly, your function safely calls your GameState and updates the local copy of it when you call it. But what is that double arrow in your blueprint ? (after ‘isValid’)
Sorry im a bit new to this and I still need to understand the hierarchy and classes better, it is not always very clear what I can access and when
Alright that was it !!!
So yes, by simply closing the animation BP in which the function is (and the character preview), I only get the Valid return.
thats crazy
The variable you are caching is a pointer to an object (or to be precise memory where this object is stored), so all variables inside it will be accessible in modified state at any time, so you can safely chache it and access from any place in code you need.
(Just in case this works only with classes but not structures or simple variables like ints or bools)
Double arrow is a reroute node, in unreal blueprint it is seen as a dot.
And don’t worry we all started learning unreal and coding at some point )