I’m currently working on a simple inventory system for my player. I have four variables, one for each “slot”, and the player can select each of them to either select what is stored, or store something in them. Exactly how this works is not relevant right now though.
There’s a point in the script where I need to check if there is something stored in the variable already. All items stored in this variable is from the base actor class ItemBP. I’m using the IsValid node a lot in this script, but this time it always returns false, even though there should be a valid variable stored in it.
Here’s an image of the event. As you can see, it checks the variable and prints the name of it. It then executes a function with an input for the validity of the variable.
In the function, there’s a branch connected to the input. If an item is valid, it should print Valid.
And here’s what I get when testing it.
As you can see, it prints the name of the object, which, in my logic, means that the variable should be perfectly valid. But it still returns invalid for some reason. What is the problem here?
Just let me know if something is unclear.
Ok, but it just means there’s nothing in the slot. Can you show your code for putting something in the slot?
I don’t understand, if the Print String node is able to print the name of the object in the slot, how can the slot be empty? I tested it when the slot was empty too, and the print string ends up printing nothing because there is nothing to print.
What do you get if you print the object name instead of display name?
I can’t generate this error, what are you doing with the object further down that line in the function?
I tried changing from display name to object name. The result is exactly the same, except now it prints a _C_0 at the end of the display name. Which means that it is definitely referencing something.
here’s an image of the rest of the function, but its not worth looking at as it never gets past the branch anyways.
But I think I might know what the problem is. The system includes a way for the player to hold things in their hands, and then store these items in the inventory. To store something in the inventory, I copy the variable from the hand, and set it to one of the inventory variables before I delete the actor in the hand to hide it. I think this means I basically have a reference to an object that does not exist in the world, but the variable still contains the name of that object. I’ll let you know if I figure it out.
I changed the variable type from actor to class, now it works as it should.