Runtime Item Pickup

maherar

Member
I created an item and its object for runtime pickup. If I simply place this and pick it up, it's okay and working well, the item and 1st person's arms are visible. But if increase the radius of the Sphere Collider or enable the "ItemPickup.cs" component at runtime, The item is picked up but not visible and 1st person's arms are not active too. I have this kind of senior where I need to instantiate the pickup item and then after a certien function execution it will be able to pickup.
 
You can pick the item up by code really easily, If you have Ultimate Seating Controller, check out the setup for the "Item Pickup Hack" objects. And look into the VehicleWeaponShooter.Register() void. Although these pickups are not created at runtime, they are never ever visible or enabled and require nothing special, they are just a reference to make it easy.
 
The size of the collider should not make a difference. Can you reproduce the issue in the demo scene so we can analyze it? It might be that the pickup is not correctly initialized when the component is enabled at runtime. You can put a debug log statement in the Initialize() function of the ItemPickup to see if it is ever called in your setup.
 
I am instantiating pickup items, in front of player and getting following expectations. I already added items to the Item manger too. What is this? how to fix it? I didn't try to write/change any of following mentioned scripts.

1666107432974.png
1666107634054.png
 
You have to set a breakpoint in line 273 and see which object is null. Without any hint on how to reproduce the error it is difficult to say what is going wrong.
 
You have to set a breakpoint in line 273 and see which object is null. Without any hint on how to reproduce the error it is difficult to say what is going wrong.
It is showing me on every item.
This line is throughing the exception
C#:
itemSetList[j].ItemIdentifiers[item.SlotID]
I have 6 items and each of them have "Slot ID = 0"

Would you please tell me how to fix it? Here is my configuration according to the demo scene.
 

Attachments

  • Items_Error.jpg
    Items_Error.jpg
    406.6 KB · Views: 3
Last edited:
What is null on that line?
I tried to debug following all but getting Null Expection only for last Line.
Please have a look. I irretated with this error.

C#:
Debug.Log($"1 {item.ItemIdentifier}");
Debug.Log($"2 {itemSetList[j]}");
Debug.Log($"3 {item.SlotID}");
Debug.Log($"4 {itemSetList[j].ItemIdentifiers[item.SlotID]} ");
 
Line 272 is a comment in the latest version. What is the line that it is having trouble on? I can't see anywhere that it would cause a problem with the ItemIdentifier being null.
 
While checking for this condition through error message.

if (itemSetList[j].ItemIdentifiers[item.SlotID] == item.ItemIdentifier) { addItemSet = false; break; }
 
I'm not sure why it would be throwing an exception. If itemSetList[j].ItemIdentifiers[item.slotID] is null then that's no problem. Maybe the item is null? If you are able to tell me how to reproduce the error within the demo scene I can take a closer look.
 
I'm not sure why it would be throwing an exception. If itemSetList[j].ItemIdentifiers[item.slotID] is null then that's no problem. Maybe the item is null? If you are able to tell me how to reproduce the error within the demo scene I can take a closer look.
I am not 100% sure how to regenerate with a new project.
But I have five boxes for runtime item pickup and one paper object. Whenever I change something in it, I will see these errors.
Just turn off play mode and restart everything is fine.
 
What do you mean change something in it?
For example, Animator Item ID, Equipe or Unequip animation event, or scripting with the Equipe or Unequip function, adding and removing inventory components from the runtime pickups list, etc. Then, most of the time, this error will occur on the first attempt, and it will be fine on the second attempt.
 
Last edited:
Unfortunately without being able to reproduce it I'm not sure what is going on. The condition "if (null == item.ItemIdentifier)" would not throw a null reference exception so I don't know why you are getting the error that you are.
 
Unfortunately without being able to reproduce it I'm not sure what is going on. The condition "if (null == item.ItemIdentifier)" would not throw a null reference exception so I don't know why you are getting the error that you are.
I said that on my current project, reproducing this error is easy. but I am not 100% sure about a new project.
Is it possible for you to tell me the steps you'd like to know? I'll reproduce the error by following all steps and send you a video click.
Or, I am ready for a shot call with screensharing if that suits you.
 
I am not sure what the error is being caused by so I need some reproduction steps.
 
Top