#Hey I need some help please The code for
1 messages ยท Page 1 of 1 (latest)
So, can you explain which line of code on what script is actually firing the error? I just got confused by all those parts ๐
here I can collect and even use all the items. Each item in the inventory above has a scriptable Object attached. At this point everything is already in the dictionary so now when I click on the weapon it goes to the equip slot at the bottom. Then the weapon needs to spawn in the characters hands.
all I need to do is read the ScriptableObject attached to the inventory slot to read the prefab.
Then instantiate the prefab into the charactes hand.
I do this in the first file I have shared.
https://gdl.space/zuyazubuna.cpp
And then the error appears
on line?
on line 49 to 53 that I commented out
Okay, just super simple question. Did you forget to assign a itemPrefab on one SO? ๐
ahahahah No XD
Could have been ๐
cause it pops up in the video for half a second
wait, it pops up?
yes.
can you debug.log instantiatedItem.transform please?
sure
I've even added my own debug to ensure I have the scriptableObject attached. Something is weird here.
the selected log is the one of transform?
and if you now alter the position, it bugs out?
wait, the code is not the issue there. It is running fine. the log gets hit with "item is now equipped"
well it bugs out regardless. when I remove the code alltogther it's fine again
Ya
it's super weird
select the stacktrace again of your error pls
yeah, I did. can you select your error and show the stacktrace?
I am more than happy to jump into a voice channel if you are comfortable
sure 1 sec
InventoryManager line 43, what is this doing again
and cant go voice, hopping back and forth with clients on google meet ๐
yep...
when equipping the item It tries to add it again and it can't becase this time there was no item collected
hmmmm
also do not call your object gameObject, because gameObject is already representing your actual gameObject the component is attached to ๐
ohhh, and on next line you try to get the component, but on the wrong gameObject I guess ? ๐
But if you say line 43, then either the dict or the itemCollected might be null
in what class sorry ?
right here
Ah, that does seem right but It still does not make sense to me. Why would the only differnce be me isntantiating a game Object and me just equipping it break things.
check this out:
Removing this
I can now equip the weapon
and use it
What? Are you instantiating it two times? ๐
so now the millioin dollar question is, why on earth can I not just add the gameObject to the world. ๐
Is your item doing something on generating it?
no, my thought process would be, I pick up the item
It gets added to the inventory slot where a copy of the scriptableObject also is stored. Upon equipping the item, pass the SO to the instantiation code to get the prefab to spawn it into the players hands.
To me this should be simple right ? but yet I am having a hard time with it
I am wondering why you do all that casting
your iteamScriptableObject is already type of Item
Oh, I have item SO as the parent and then I have a weapon SO, throwable SO , consumable SO
itemScriptableObject.itemPrefab should be enough to call
I just pass in the generic SO and cast to item or weapon or consumable
(Item) should be enough
Okay. Well, let me give this another try by removing the casting and then see what happens
and can you do this, without any var and stuff. just instantiate and see what happens
Instantiate(itemPrefab, GameObject.Find("Hand.R").transform, true);
did you check your ahdn transform, is it there somehow?
like in the hierarchy?
๐
now lets revert back to your code and see, what could be the issue
so what was your current code thats working?
ahahaha this is pretty funny
That is far off ๐
at 0. 0 .0
I am confused by your setup ๐
Okay, anyway. lets see what happens if we set the localposition to zero ๐
XD alright
GameObject instantiatedItem = Instantiate(itemScriptableObject.itemPrefab, GameObject.Find("Hand.R").transform, true);
instantiatedItem.transform.localPosition = Vector3.zero;
In my defence this is the first big project I am tackeling and I have a devlog series up on the tubes about everything I have so far .
I can't store the instantiated object as a gameObject strangely enough
what the heck, why cant you get an gameobject back from instantiate ๐
Weird, feels like I never used unity on the simplest things right now ๐
I'm doing it fine in the inventory manager for the item slots
What is your itemPrefab? what type, its gameobject or item?
Things start to get super weird here ๐
The prefab attached to the SO
maybe I should just remove everything I don't need and try again
what if you instantiate as GameObject, does this work at least?
Just make var to GameObject and cast it and see if you get the error again
Gotta go in some minutes unfortunately, but will remain in this thread and check later. I wait for your response about the casting tho ๐
๐ Don't judge, I can instantiate as GameObject.. would help if I passed in the right type of SO though ....
๐
here you go : https://www.youtube.com/channel/UCXBRt4DewvNqZYH93DOLzeA
Hi there! My name is Garreth Dean, and I'm an aspiring indie game developer. I'm a huge fan of playing games and I really want to push past my limits to produce a game I can be proud of. On my channel, I typically showcase my current projects and also how I make them. If you're interested in learning more about the current game I am developing, ...
That worked btw but
OMG
subscribed btw, but what? ๐
DUde the other script worked and because it attached to my arm the character was triggering the pickup script and because it was instantiated without a gameobject you get the error.. Check this out hahah
hahahah I can't believe this
the code was working all along. It was my dumb ss not using a clean gameObject
๐
Yeah, using vars can just lead to missing casting and recognition of wrong types ๐ I try to avoid var as much as I can ๐
You might wanna simplify your script if possible at some point ๐ Alrighty, gotta go, time for some dad duties over here. see ya later ๐
Same to you and always a pleasure to help. Happy developing ๐
๐ฅณ Real MVP
Hey, going to just drop this here . I am struggeling to get the rotation and position correct of the weapon I spawn. I can't get it to spawn into the hand correctly
I am sure, thats a minor issue. And putting something in the correct position will hunt you across game dev anyway, so I would not avoid that ๐