Instantiate Object From Script - No Color Error

Hi, Ive been trying to get back into unity and am finally starting to make my dream game! I’ve been prototyping bits and pieces that will be required to make my game work. However a vital component for my game I can’t seem to get working. Instantiating an object via a script INCLUDING it’s color. Ive made a test object in MagicaVoxel and exported it as an .obj. I can drag the object onto the scene and drag the colors also generated from MagicaVoxel for the colors to appear. However when I instantiate the object with code it just appears white. Ive been trying in code to load the material and add it to the Renderer of the object the mesh Renderer to no avail. If anyone knows the code to do this it would be a great help thanks :slight_smile:

	GameObject gO =
			new Vector3(5, 5, 5),
			Quaternion.identity) as GameObject;
	gO.GetComponent<Renderer> ().material = Resources.Load("preFabColTest", typeof(Material)) as Material;


Welcome to our forum! :slight_smile:

Your code looks fine. As long as you do not share more specific information on your problem, it’s impossible to help you.

I googled this thread for you:

Solved - When I exported from Voxel it created 3 files but I accidentally didn’t import the 3rd… Thank you all for your help :slight_smile:

I’m glad you figured the solution out by yourself. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms