I’m trying to make a simple mechanic where you get water put it in the water dispenser and the bottle disappears.
here’s the code:
but the problem is that the cast to the actor you carry either fails or doesn’t cast at all.
I tried putting a sequence after the 1st branch and run it but when I tried it with some “print string” nodes it didn’t cast at all. And I also tried putting it at the as you can see in the screenshot but when I put the string nodes it showed that the cast failed.
So my question is why is the cast failing and what am I doing wrong here?
If you need any further info just ask me. Thanks in advance.
It will because you’ve made a variable of the correct type, but has not assigned it to anything.
I can’t actually read your code, because it’s so small, but if that reference at the start is to a bottle ( for instance ), how is the system meant to know which bottle you’re talking about. You might have 10000 bottles in the scene.
You need to assign your bottle ( or whatever ) to the variable…
I assume you’re getting the ‘none’ error when you end play.
I am not 100% sure if you are talking about these variables but here is how I made the variables for the cast object.
I know I’m probably not of much help with this message but not fully understanding English + my basic unreal engine knowledge is preventing me from fully understanding what you mean.
This
Can you show the error?
When you use ‘get actor of class’, one has to exist. Are they already in the level?
This cast has a blue line underneath, that tells you, you don’t need to cast
1 Like
This is the error message I get when I don’t cast to it and I just connect the reference to destroy actor:
and yes the first ‘get all actors’ is in the level but the second one I spawn in the level when I get water.
Ok, so your ‘bottleOwater’ variable is not pointing to anything
When you spawn it, that gives you the reference to plug into the destroy node.
Aaand… how do I fix it? (i typed it really slow like you can see just to show that I know the answer I pretty obvious but I still can’t see it)
If you’re spawning it in the same BP, then you’ve already got it.
If you’re spawning it somewhere else, then you can use ‘get actor of class’, once it’s in the world, to get the reference.