- Home /
Instantiated Object Wont save a reference to the prefab, instead sets to itself
Weird Problem I have encountered. So for my game i need to add 100s of different weapons. Now right now i have to add more code for every weapon to check if the mags are for the weapon when reloading. I need to combat this because it is impractical. So i have some code right here.
if (HasMag == false && other.GetComponent<MagScript>() != null && MagPrefab.name == other.GetComponent<CanInteractWithThis>().MagPrefab.name) {
I assign the mag prefab into the gun spot in the inspector. Like so.
Then with the mag i do the same. the mag and the gun have the same script on them. The code above is suppose to check if the names are the same and if so let the reload occur, but here is the weird thing. When i instantiate the mag. The inspector no longer shows the assigned prefab on the mag to be the prefab, it assigns it to be itself. Like so. .
Is there any way to get around this or maybe a different way to check? Thanks for taking the time to read the text wall, and thanks to everyone who will help.
Answer by SPOTNINJADUD7890 · Sep 10, 2018 at 03:56 AM
I made it work using a string i can put in the inspector but if anyone has an answer to this i would really like to know.