Jump to content

Get Entity Target


AggrorJorn
 Share

Recommended Posts

I am working on a simple Tower defense tech demo and I have a little problem.

I want to address a roadnode in the editor via C#. After that, I want to make a simple loop that goes though the nodes with GetEntityTarget.

At the moment I search for the first road node in a level. Then I loop through the roadnodes to get a list that represents the path.

 

The problem is, that it can not find a target in the scene, while the road nodes are deffinitly connected in the editor.

 

 

//Load the first level
		    TEntity level1 = LE.LoadScene("abstract::level1.sbx");

		    //Get the path
		    TEntity currentNode = LE.FindChild(level1, "node_1");
		    List<TVec3> path = new List<TVec3>();
		    bool pathEnded = false;
		    while(pathEnded == false)
		    {
			    TEntity nextNode = LE.GetEntityTarget(currentNode);
			    if (nextNode == null)
				    pathEnded = true;
			    else
			    {
				    path.Add(LE.EntityPosition(nextNode));
				    currentNode = nextNode;					   
			    }
		    }

Link to comment
Share on other sites

TEntity currentNode = LE.FindChild(level1, "node_1");

 

Is that line working? Is it finding anything? Not sure if that's a C# LE thing, but normally you have to loop through entities with GetChild() and then by index not name. Then you use GetEntityKey() on each index looking for the "name" key and checking that to what you are looking for.

Link to comment
Share on other sites

Thanks for the answer Rick. As far as I can tell, it does find the object using only FindChild. To make sure that is it correct I have its name checked


//Find the correct index with GetChild
				TEntity entTemp = LE.FindChild(level1,"node_1");//LE.GetChild(level1, i);

				//After every child index has been found, use GetEntityKey to search for Object with a name
				if (LE.GetEntityKey(entTemp, "name") == "node_1")
					Console.WriteLine(LE.GetEntityKey(entTemp, "name").ToString);

 

I see now where the problem lies. I get the entity target but that target can be null. I get a system protected memory error. I think I can find whats wrong now.

 

Just have to find out how I can solve this.

Link to comment
Share on other sites

How can I prevent that an entity has not target and thereby crashes the program?

 

//Get the path
		    TEntity currentNode = LE.FindChild(level1, "node_1");
		    Console.WriteLine(currentNode.ToString());
		    bool pathEnded = false;
		    while(pathEnded == false)
		    {
			    TEntity nextNode;
			    if (LE.GetEntityTarget(currentNode) != null)
			    {
				    nextNode = LE.GetEntityTarget(currentNode);
				    Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString());
				    path.Add(LE.EntityPosition(nextNode));
				    currentNode = nextNode;
			    }
			    else
				    pathEnded = true;
		    }

 

the log reports that it finds all the nodes now, but as soon as the target is not present, my programm crashes.

Link to comment
Share on other sites

I think he's referring to this:

 

   nextNode = LE.GetEntityTarget(currentNode);
   Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString());

you are using nextNode without checking that it's not NULL

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Isn't this line doing that?

if (LE.GetEntityTarget(currentNode) != null)

 

Sorry, I didn't pay attention.

 

May be crash occurs after that loop?

 

Or try to comment these lines out. May be the error occurs somewhere here:

     Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString());
     path.Add(LE.EntityPosition(nextNode));

Link to comment
Share on other sites

@Pixel: I am not sure I understand what you mean. If the target is null

if (LE.GetEntityTarget(currentNode) != null)

Then these lines shouldn't be executed

nextNode = LE.GetEntityTarget(currentNode);
Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString());

 

@Rick

The script finds the models (see screenshot). And since there is no 17th node, the loop should stop.

post-45-0-11448300-1332172821.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...