Question by
MilesHoyland · Apr 05, 2019 at 08:20 PM ·
gameobjectscripting beginnerinstantiate prefab
Object reference not set to an instance of an object when trying to instantiate
Sorry if this is pretty basic, new to unity, but i'm trying to instantiate a projectile prefab using the transforms of an empty GameObject within my scene (as the spawn point), however I am getting thrown this error:
NullReferenceException: Object reference not set to an instance of an object FireCatapult.Update () (at Assets/Scripts/FireCatapult.cs:55)
Any help would be greatly appreciated, thanks !
Here's the chunk of code where i'm getting the issue:
private void Update()
{
if (!CurrentlyLoaded)
{
projectileInstance = Instantiate(projectilePrefab, projectileStartPosTr.position, projectileStartPosTr.rotation);
hitMe = projectileInstance.GetComponent<Rigidbody>();
CurrentlyLoaded = true;
}
}
Comment
Your answer