[C#] how to add a primitive in this script???

Hi everyone,
I working on a project trying to plot a nodes-edges representation but right now it just renders edges… how can I add a sphere primitive as node to get both gameObjects??

here is the script:

// nodes
foreach (Transform location in subregion)
        int nodeindex = System.Convert.ToInt16(location.gameObject.name);
        atlasRegionSubregionLocation currentNode  = connectomeModel.NodesGlobalIndexer[nodeindex] as atlasRegionSubregionLocation;
        int edgeinstanceIndex = 0; 
        foreach (int edgeIndex in currentNode.EdgeTo)
            ConnectomeModel.Edge currentEdge = connectomeModel.Edges[edgeIndex];
            // Look for gameobjects representing edges
            Vector3 fromCoord = (GameObject.Find(currentEdge.NodeFrom.ToString())).transform.position;
            //should be here??					
            GameObject sphere = (GameObject.CreatePrimitive(PrimitiveType.Sphere.currentEdge.NodeFrom.ToString())).transform.position;

            // transform to local region
            fromCoord = fromCoord - subregion.transform.position;
            Vector3 toCoord =  (GameObject.Find(currentEdge.NodeTo.ToString())).transform.position;
            toCoord = toCoord - subregion.transform.position;
            instanceEdge(fromCoord , toCoord , (float)currentEdge.Weight  * 1.5f +  0.5f, edgeinstanceIndex, ref tempEdges, ref tempTriangles);

thanks in advance

Looks like you’re created a new primitive, here:

GameObject sphere = (GameObject.CreatePrimitive(PrimitiveType.Sphere.currentEdge.NodeFrom.ToString())).transform.position;

Problem with that, though, is you don’t seem to be setting the new GameObject’s position. It might also be a good idea to parent it to some other object, to keep your scene hierarchy organized. Both of these can be achieved through the new object’s transform.

You can see some simple examples here.

If this is an editor-only feature you’re looking into, you might also consider using Gizmos to draw spheres, lines, and so on.

GameObject sphere = (GameObject.CreatePrimitive(PrimitiveType.Sphere.currentEdge.NodeFrom.ToString())).transform.position;

Umh, this line doesn’t make sense, this won’t even compile. You’re trying to dereference “PrimitiveType.Sphere”, and casting the transform.position to a GameObject…

Try something like this:

GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

i just realized that, thanks!
now I want to assign a certain size to the spheres and parent them to an empty object, but it doesn’t work yet…

any idea?