ArgumentException: The thing you want to instantiate is null.
I apologize for my poor English. I do my best to describe the situation in a clear way. I have set a Transform object in Awake() method from Resources folder. I don't get any exception in Awake() or Start(), but when I instantiate my assigned Transform, I get ArgumentException:
this is my code:
public class WeaponScript : MonoBehaviour {
public Transform shotPrefab;
void Awake()
{
if (GetComponent<PlayerScript>() != null && PlayerPrefs.HasKey("BoughtShot2"))
{
Debug.Log("shot is shot2");
// I assign this property here.
shotPrefab = (Resources.Load("Shots/PlayerShot2")) as Transform;
}
}
public void Attack(bool isEnemy)
{
// Create a new shot, I get my exception in this line:
var shotTransform = Instantiate(shotPrefab) as Transform;
}
}
I don't want to assign shotPrefab
in inspector. I need to instantiate a transform based on user In-App purchase.
How can I fix it? Should I initialize shotPrefab
in another way? I tried initializing it both in Awake() and Start() but I faced this problem again.
Thanks in advance. :-)
Your answer
![](https://koobas.hobune.stream/wayback/20220612051501im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity 2d Collision Glitch Help 0 Answers
Make custom game launcher 1 Answer
How to decreased the visible particles 0 Answers
How to save an image on Android? 0 Answers
Script editor not recognising Unity specific code?! 0 Answers