Script Default Properties Behaviour

I must be missing something.

I’m trying to set the default properties of my scripts, but the global/public values don’t show up in the Inspector.
I looked through my other scripts to see if any values had shown up and where they do, they were out-dated (properties that I had added at one point, but then removed or made private).

Though as I’m playing with it, I’m also finding that it behaves strangely. As I can assign ints, but not floats, and I can assign Vector sizes but not the values.

Thanks

The default properties are only for references to other objects. This is because references can not be set in the script. All other properties can have default values defined in the script, so no need for having one more layer of indirection.

Thanks, it makes sense that you can only set reference values. But you are saying that I can set reference values of scripts?

Here’s what I did, perhaps you can tell me what I did wrong:
(The default properties inspector still seems a bit finicky about when it displays the public variables of my script.)

Essentially, I’m creating a class that is initialized with two nodes(Vector3 positions), the ability to calculate points between those nodes, and an unassigned line renderer. The renderer in this case is a prefab (“Line”) with a line renderer and “PathEdgeRender.cs” script attached.

I select the PathEdge.cs script directly from my scripts folder (“standard assets/scripts”), and then drag “Line” onto PathEdge:edge_renderer in the Inspector.

public class PathEdge {

public PathEdgeRender edge_render= null;  // object to render edge
private PathEdgeRender inst_edge_render= null;  // instance rendered edge

public PathEdge(Node node1, Node node2) {

if (edge_render == null) { Debug.Log("I set you in the inspector!"); }

inst_edge_render= (PathEdgeRender)Object.Instantiate(edge_render, node1.GetPosition(), Quaternion.identity); // NULL REFERENCE

inst_edge_render.SetPath(this);
}
}

I fire up the code and get a NullReference, in regards to the edge_render.

Can I not use the Default Properties editor like this? Does it only work with Prefab values? And if I can’t do this, there wouldn’t be a “FindAsset()” routine for runtime would there?

I can make this work if I pass edge_render down from the gameobject that is making the edge, and assigning it to the default values of the prefab.

thanks very much

Default properties are just that. Default properties, they will not override whatever you have setup in the inspector. So if you have a game object (prefab or in the scene) using the script, you have to make sure the script attached to the game object has the reference assigned correctly.

What you have set up in the default references matters only so far that when you add the script to an object, it will default to those references. So the default properties are for convenience only. When you have an unassigned reference somewhere, look in the game object not in the default properties.