Error cs1729 vector3 does not contain a constructor that takes 1 arguments

I keep trying to catch what I did wrong but I can't. Can someone help me? It says that error CS1729: 'Vector3' does not contain a constructor that takes 1 arguments. My code: using System.Collec...

I keep trying to catch what I did wrong but I can’t. Can someone help me? It says that

error CS1729: 'Vector3' does not contain a constructor that takes 1 arguments.

My code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetAxisRaw("Horizontal") > 0.5f)
        {
            transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime));
        }
    }
}

Izaak van Dongen's user avatar

asked Jan 25, 2020 at 15:48

Dinis Aio's user avatar

1

The Vector3 struct in System.Numerics does indeed have a constructor which accepts a single float as an argument. (Which internally applies that one value to all three properties of the vector.)

However, you’re not using System.Numerics in your code. It looks like UnityEngine has a different Vector3 struct. And it has only one constructor:

public Vector3(float x, float y, float z);

So to use it you’ll need to supply all three values being used in the vector. Perhaps you meant to separate the values instead of multiply them?:

new Vector3(Input.GetAxisRaw("Horizontal"), moveSpeed, Time.deltaTime)

If you meant something else then you’d need to define the values you want to use.

answered Jan 25, 2020 at 16:02

David's user avatar

DavidDavid

201k35 gold badges195 silver badges271 bronze badges

Vector 3 takes 3 arguments. X, Y and Z value. You just need to put that Input.GetAxisRaw(«Horizontal») * moveSpeed * Time.deltaTime) in the x position like this
Transform.Translate(new Vector3(Input.GetAxisRaw(«Horizontal») * moveSpeed * Time.deltaTime, 0, 0))

answered Jan 25, 2020 at 16:04

Rasmus Kirvesmäki's user avatar

Permalink

Cannot retrieve contributors at this time

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Compiler Error CS1729

Compiler Error CS1729

07/20/2015

CS1729

CS1729

69d24ae0-eaca-4fbf-a5f3-70791f43f97a

Compiler Error CS1729

‘type’ does not contain a constructor that takes ‘number’ arguments.

This error occurs when you either directly or indirectly invoke the constructor of a class but the compiler cannot find any constructors with the same number of parameters. In the following example, the test class has no constructors that take any arguments. It therefore has only a parameterless constructor that takes zero arguments. Because in the second line in which the error is generated, the derived class declares no constructors of its own, the compiler provides a parameterless constructor. That constructor invokes a parameterless constructor in the base class. Because the base class has no such constructor, CS1729 is generated.

To correct this error

  1. Adjust the number of parameters in the call to the constructor.

  2. Modify the class to provide a constructor with the parameters you must call.

  3. Provide a parameterless constructor in the base class.

Example

The following example generates CS1729:

// cs1729.cs  
class Test  
{  
    static int Main()  
    {  
        // Class Test has only a parameterless constructor, which takes no arguments.  
        Test test1 = new Test(2); // CS1729  
        // The following line resolves the error.  
        Test test2 = new Test();  
  
        // Class Parent has only one constructor, which takes two int parameters.  
        Parent exampleParent1 = new Parent(10); // CS1729  
        // The following line resolves the error.  
        Parent exampleParent2 = new Parent(10, 1);  
  
        return 1;  
    }  
}  
  
public class Parent  
{  
    // The only constructor for this class has two parameters.  
    public Parent(int i, int j) { }  
}  
  
// The following declaration causes a compiler error because class Parent  
// does not have a constructor that takes no arguments. The declaration of  
// class Child2 shows how to resolve this error.  
public class Child : Parent { } // CS1729  
  
public class Child2 : Parent  
{  
    // The constructor for Child2 has only one parameter. To access the
    // constructor in Parent, and prevent this compiler error, you must provide
    // a value for the second parameter of Parent. The following example provides 0.  
    public Child2(int k)  
        : base(k, 0)  
    {  
        // Add the body of the constructor here.  
    }  
}  

See also

  • Inheritance
  • Constructors

  • Remove From My Forums
  • Question

  • i have been creating data types for people and the «Date» type is from

    Here and with inheritance i get CS1729

    Code 

    //generic.cs
    //Copyright 2014 Emersont1
    using System;
    using People;
    namespace People
    {
    
    	public class Person
    	{
    		
    		/// <summary>
    		/// Is the referenced person Dead? True for dead
    		/// </summary>
    		bool IsDead;
    		/// <summary>
    		/// The name of the person expressed as a name class
    		/// </summary>
    		public NameDataType Name;
    		/// <summary>
    		/// The date of birth of the person
    		/// </summary>
    		public Date DateOfBirth;
    		/// <summary>
    		/// The gender. True For Male, false for Female
    		/// </summary>
    		public bool Gender;
    		/// <summary>
    		/// Initializes a new instance of the <see cref="People.Generic"/> class.
    		/// </summary>
    		/// <param name="nme">Nme.</param>
    		/// <param name="dob">Dob.</param>
    		/// <param name="sex">If set to <c>true</c> male</param>
    		public Person(NameDataType nme, Date dob, bool sex)
    		{
    			Name = nme;
    			DateOfBirth = dob;
    			Gender = sex;
    		}
    		
    	}
    }
    
    //Dead.cs
    //Copyright 2014 Emersont1
    using System;
    using People;
    
    namespace People
    {
    	/// <summary>
    	/// Description of Dead.
    	/// </summary>
    	public class Dead : Person
    	{
    		public Date DateOfDeath;
    		bool isdead = true;
    		public Dead(NameDataType nme, Date dob, bool sex)
    		{	
    			Name = nme;
    			DateOfBirth = dob;
    			Gender = sex;			
    		}
    	}
    }

    any help will be appreciated

Answers

  • The error is caused by two things:

    1) your base class has no simple constructor with zero arguments.

    2) your inherited class overrides the non-simple constructor in the wrong way.

    E.g. this works:

        public class Date { }
        public class NameDataType { }
        public class Person
        {
            public NameDataType Name;
            public Date DateOfBirth;
            public bool Gender;
            public Person(NameDataType name, Date dateOfBirth, bool gender)
            {
                this.Name = name;
                this.DateOfBirth = dateOfBirth;
                this.Gender = gender;
            }
    
        }
        public class Dead : Person
        {
            public Date DateOfDeath;        
            public Dead(NameDataType name, Date dateOfBirth, bool gender, Date dateOfDeath)
                : base(name, dateOfBirth, gender)
            {
                this.DateOfBirth = dateOfDeath;
            }
        }

     btw, use explitict name, correct spelling, no unnecessary acronyms. Then your code is much more readable and easier to understand.

    • Proposed as answer by

      Tuesday, November 25, 2014 3:19 AM

    • Marked as answer by
      Kristin Xie
      Tuesday, November 25, 2014 3:23 AM

  • CS1729 = ‘type’ does not contain a constructor that takes ‘number’ arguments.

    I’m guessing the error occurs on this statement:

    public Date DateOfDeath;

    Looking at the Date struct definition, I find two constructors, both parameterized:

    public Date(int year,
    int
    month, int day)

    and

    public Date(DateTime dateTime)

    BUT, no default constructor

    public Date()

    So, you cannot instantiate Date unless you pass either three ints or one DateTime object to properly invoke one of the defined constructors.

    • Marked as answer by
      Kristin Xie
      Tuesday, November 25, 2014 3:23 AM

Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Posted by Hamid Baniasadi

I was following the videos and when I clicked play to check the idle animation for the player prefab to loop and play an error pops up saying «error CS1729: The type UnityEngine.Vector3' does not contain a constructor that takes1′ arguments» if anyone has a solution to this problem please give me an answer

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

private Animator playerAnimator;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;

// Use this for initialization
void Start (){


}
// Update is called once per frame
    void Update () {
    moveHorizontal = Input.GetAxisRaw ("Horizontal");
    moveVertical = Input.GetAxisRaw ("Vertical");

    movement = new Vector3 ("moveHorizontal, 0.0f, moveVertical");
}

}

Thanks!

1 Answer

Seth Kroger

Your last line shouldn’t have any quote marks in it. The constructor is supposed to take three numbers. Using the quote marks like you did turns it into a literal string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
 
[CustomEditor(typeof(vp_FootstepManager))]
 
public class vp_FootstepManagerEditor : Editor
{
 
    // target component
    public vp_FootstepManager m_Component;
 
    // foldouts
    public static bool m_SurfaceTypesFoldout;
    
    protected static GUIStyle m_HeaderStyle = null;
    protected static GUIStyle m_SmallButtonStyle = null;
    
    static public Texture2D blankTexture
    {
        get
        {
            return EditorGUIUtility.whiteTexture;
        }
    }
    
    public static GUIStyle SmallButtonStyle
    {
        get
        {
            if (m_SmallButtonStyle == null)
            {
                m_SmallButtonStyle = new GUIStyle("Button");
                m_SmallButtonStyle.fontSize = 10;
                m_SmallButtonStyle.alignment = TextAnchor.MiddleCenter;
                m_SmallButtonStyle.margin.left = 1;
                m_SmallButtonStyle.margin.right = 1;
                m_SmallButtonStyle.padding = new RectOffset(0, 4, 0, 2);
            }
            return m_SmallButtonStyle;
        }
    }
 
 
    public static GUIStyle HeaderStyleSelected
    {
        get
        {
            if (m_HeaderStyle == null)
            {
                m_HeaderStyle = new GUIStyle("Foldout");
                m_HeaderStyle.fontSize = 11;
                m_HeaderStyle.fontStyle = FontStyle.Bold;
                
            }
            return m_HeaderStyle;
        }
    }
 
 
 
    /// <summary>
    /// hooks up the component object as the inspector target
    /// </summary>
    public virtual void OnEnable()
    {
 
        m_Component = (vp_FootstepManager)target;
        m_Component.SetDirty(true);
 
    }
 
    /// <summary>
    /// 
    /// </summary>
    public override void OnInspectorGUI()
    {
 
        GUI.color = Color.white;
 
        DoSurfaceTypesFoldout();
 
        // update
        if (GUI.changed)
        {
 
            EditorUtility.SetDirty(target);
 
        }
 
    }
 
    /// <summary>
    /// 
    /// </summary>
    public virtual void DoSurfaceTypesFoldout()
    {
        
        if (m_Component.SurfaceTypes != null)
        {
            for (int i = 0; i < m_Component.SurfaceTypes.Count; ++i)
            {
 
                vp_FootstepManager.vp_SurfaceTypes surface = m_Component.SurfaceTypes[i];
                
                GUILayout.BeginHorizontal();
                GUILayout.Space(20);
                surface.Foldout = EditorGUILayout.Foldout(surface.Foldout, surface.SurfaceName);
                if(i > 0)
                {
                    if (GUILayout.Button("^", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
                    {
                        int newIndex = i-1;
                        List<vp_FootstepManager.vp_SurfaceTypes> newSurfaces = new List<vp_FootstepManager.vp_SurfaceTypes>();
                        for(int x = 0; x < m_Component.SurfaceTypes.Count; x++)
                        {
                            vp_FootstepManager.vp_SurfaceTypes surf = m_Component.SurfaceTypes[x];
                            if(x == newIndex)
                            {
                                newSurfaces.Add(surface);
                                newSurfaces.Add(surf);
                            }
                            else if(surf != surface)
                                newSurfaces.Add(surf);
                        }
                        m_Component.SurfaceTypes = newSurfaces;
                        m_Component.SetDirty(true);
                        return;
                    }
                    GUILayout.Space(5);
                }
                
                if (GUILayout.Button("Remove", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(50), GUILayout.MaxWidth(50), GUILayout.MinHeight(15)))
                {
                    m_Component.SurfaceTypes.RemoveAt(i);
                    --i;
                }
                GUI.backgroundColor = Color.white;
                
                GUILayout.Space(20);
 
                GUILayout.EndHorizontal();
                
                GUILayout.Space(5);
                
                if(surface.Foldout)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(35);
                    if(surface.SurfaceName == "")
                        surface.SurfaceName = "Surface "+(i+1);
                    surface.SurfaceName = EditorGUILayout.TextField("Surface Name", surface.SurfaceName, GUILayout.MaxWidth(250));
                    GUILayout.EndHorizontal();
                    
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(35);
                    surface.RandomPitch = EditorGUILayout.Vector2Field("Random Pitch", surface.RandomPitch);
                    GUILayout.EndHorizontal();
                    
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(38);
 
                    if (surface.SoundsFoldout)
                        surface.SoundsFoldout = EditorGUILayout.Foldout(surface.SoundsFoldout, "Sounds", HeaderStyleSelected);
                    else
                        surface.SoundsFoldout = EditorGUILayout.Foldout(surface.SoundsFoldout, "Sounds");
                    GUILayout.EndHorizontal();
                    
                    if(surface.SoundsFoldout)
                    {
                        if(surface.Sounds != null)
                        {
                            if(surface.Sounds.Count > 0)
                            {
                                for (int x = 0; x < surface.Sounds.Count; ++x)
                                {
                                    GUILayout.BeginHorizontal();
                                    GUILayout.Space(50);
                                    surface.Sounds[x] = (AudioClip)EditorGUILayout.ObjectField("", surface.Sounds[x], typeof(AudioClip), false);
                                    if (surface.Sounds[x] == null)
                                        GUI.enabled = false;
                                    if (GUILayout.Button(">", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
                                    {
                                        AudioSource audio = m_Component.transform.root.GetComponentInChildren<AudioSource>();
                                        if (audio != null)
                                            audio.PlayOneShot(surface.Sounds[x]);
                                    }
                                    GUI.enabled = true;
                                    if (GUILayout.Button("X", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
                                    //                                  if (GUILayout.Button("X", GUILayout.Width(25), GUILayout.Height(15)))
                                    {
                                        surface.Sounds.RemoveAt(x);
                                        m_Component.SetDirty(true);
                                        --x;
                                    }
                                    GUI.backgroundColor = Color.white;
                                    GUILayout.Space(20);
 
                                    GUILayout.EndHorizontal();
                                }
                            }
                        }
                        
                        if(surface.Sounds.Count == 0)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(50);
                            EditorGUILayout.HelpBox("There are no sounds. Click the "Add Sound" button to add a sound.", MessageType.Info);
                            GUILayout.Space(20);
                            GUILayout.EndHorizontal();
                        }
                        
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Add Sound", GUILayout.MinWidth(90), GUILayout.MaxWidth(90)))
                        {
                            AudioClip clip = new AudioClip();
                            surface.Sounds.Add(clip);
                            m_Component.SetDirty(true);
                        }
                        GUI.backgroundColor = Color.white;
                        GUILayout.EndHorizontal();
                        vp_EditorGUIUtility.Separator();
 
                    }
                    
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(38);
 
                    if (surface.TexturesFoldout)
                        surface.TexturesFoldout = EditorGUILayout.Foldout(surface.TexturesFoldout, "Textures", HeaderStyleSelected);
                    else
                        surface.TexturesFoldout = EditorGUILayout.Foldout(surface.TexturesFoldout, "Textures");
 
                    GUILayout.EndHorizontal();
                    
                    if(surface.TexturesFoldout)
                    {
                        if(surface.Textures != null)
                        {
                            if(surface.Textures.Count > 0)
                            {
                                int counter = 0;
                                for (int x = 0; x < surface.Textures.Count; ++x)
                                {
                                    if(counter == 0)
                                    {
                                        GUILayout.BeginHorizontal(GUILayout.MinHeight(100));
                                        GUILayout.Space(50);
                                    }
                                    
                                    GUILayout.BeginVertical(GUILayout.MinHeight(90));
                                    surface.Textures[x] = (Texture)EditorGUILayout.ObjectField(surface.Textures[x], typeof(Texture), false, GUILayout.MinWidth(50), GUILayout.MaxWidth(75), GUILayout.MinHeight(50), GUILayout.MaxHeight(75));
 
                                    if (GUILayout.Button("Delete", GUILayout.MinWidth(50), GUILayout.MaxWidth(75)))
                                    {
                                        surface.Textures.RemoveAt(x);
                                        m_Component.SetDirty(true);
                                        --x;
                                    }
                                    GUI.backgroundColor = Color.white;
                                    GUILayout.EndVertical();
                                    
                                    counter++;
                                    
                                    if(counter == 4 || x == surface.Textures.Count - 1)
                                    {
                                        GUILayout.Space(20);
 
                                        GUILayout.EndHorizontal();
                                        counter = 0;
                                    }
                                }
                            }
                        }
                        
                        if(surface.Textures.Count == 0)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(50);
                            EditorGUILayout.HelpBox("There are no textures. Click the "Add Texture" button to add a texture.", MessageType.Info);
                            GUILayout.Space(20);
                            GUILayout.EndHorizontal();
                        }
                        
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Add Texture", GUILayout.MinWidth(90), GUILayout.MaxWidth(90)))
                        {
                            Texture texture = new Texture2D(2, 2);
                            surface.Textures.Add(texture);
                            m_Component.SetDirty(true);
                        }
                        GUI.backgroundColor = Color.white;
                        GUILayout.EndHorizontal();
                    }
                    
                    DrawSeparator();
                    
                    GUILayout.Space(5);
                }
            }
        }
        
        if(m_Component.SurfaceTypes.Count == 0)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(50);
            EditorGUILayout.HelpBox("There are no Surface Types. Click the "Add Surface Type" button to add a new surface type.", MessageType.Info);
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
        }
        
        GUILayout.Space(8f);
        
        GUILayout.BeginHorizontal();
 
        if (GUILayout.Button("Add Surface Type", GUILayout.MinWidth(150), GUILayout.MinHeight(25)))
        {
            vp_FootstepManager.vp_SurfaceTypes surface = new vp_FootstepManager.vp_SurfaceTypes();
            m_Component.SurfaceTypes.Add(surface);
        }
        GUI.backgroundColor = Color.white;
        GUILayout.EndHorizontal();
            
        DrawSeparator();
        
    }
    
    static public void DrawSeparator ()
    {
        
        GUILayout.Space(12f);
 
        if (Event.current.type == EventType.Repaint)
        {
            Texture2D tex = blankTexture;
            Rect rect = GUILayoutUtility.GetLastRect();
            GUI.color = new Color(0f, 0f, 0f, 0.25f);
            GUI.DrawTexture(new Rect(0f, rect.yMin + 10f, Screen.width, 4f), tex);
            GUI.DrawTexture(new Rect(0f, rect.yMin + 10f, Screen.width, 1f), tex);
            GUI.DrawTexture(new Rect(0f, rect.yMin + 13f, Screen.width, 1f), tex);
            GUI.color = Color.white;
        }
        
    }
    
 
}

Понравилась статья? Поделить с друзьями:
  • Error cs1529 unity
  • Error cs1525 unexpected symbol void
  • Error cs1525 unexpected symbol public
  • Error cs1525 unexpected symbol expecting
  • Error cs1525 unexpected symbol end of file